'wget' Files From Google Drive (+ online tool)

Working with different datasets across machines, in Google Colab, Kaggle Kernels or your own notebooks we sometimes need to transfer large files - from datasets, to other random fragments. A relatively easy and repeatable way to move files across is to use Google Drive. Alternatively use ‘scp’ if the platfrom supports it!

So, let’s assume that we have a file on Google Drive that we want to locally access. We can create a wget compatible link and use the cli to fetch it!

There are just two steps. First, find the file in GDrive and copy the link after changing the permission to Anyone with the link can view.

You’ll get a relatively ugly URL like https://drive.google.com/file/d/{FILE}/view?usp=sharing. If we try to wget that, it won’t sadly work. We need to get an export URL.

Second, note the {FILE} parameter in your url and substitute it here with the desired {FILENAME}:

wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id={FILE}' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id={FILE}" -O {FILENAME} && rm -rf /tmp/cookies.txt

To make things easier just paste your link below and click “Generate wget command”.

Note: Everything is processed locally on your browser, no data is stored.


Don’t miss out on more tips and tricks, subscribe to the newsletter!


The full command was adapted from here.

Related

Avatar
Daniel Angelov
PhD Student Robotics and AI

Making actual robots smarter.

Next
Previous