How to Download Google Drive Files Using WGET

Having recently had to go through the process of migrating 30+ websites, all with large backups stored on Google Drive, it became apparent how difficult and time-consuming it is to download them manually – many were over 3GB in size.

When trying to access files using the Google Drive URL, it can be quite a task. An easy alternative is to save them to your computer and upload them onto the server. Even though this could work for only one file, dealing with over 30 backups may become extremely time-consuming – days even!

No need to fret – here’s an uncomplicated solution for getting the Google Drive files onto your server with a simple wget command.

Before continuing, it is important to understand how Google Drive organizes files. Those with less than 100MB are classified as “small”, while anything over 100MB is deemed “large”.

How to Download Google Drive Files Using WGET

Before the file is downloaded it is needed to be shared publicly.

  1. To download a specific file, right-click it and select Share.
  2. This will open a dialog box in which you should click on the Advanced icon located in the bottom right corner.
  3. Under Who has access, you must select On – Public on the web before clicking Save.
  4. Copy the link for sharingExample: https://drive.google.com/file/d/1UibyVC_C2hoT_XEw15gPEwPW4yFyJFeOEA/view?usp=sharing
  5. Copy the file id from the URL “1UibyVC_C2hoT_XEw15gPEwPW4yFyJFeOEA” as needed while using the wget command.
Downloading small files using WGET (less than 100MB)

To download a small file stored on Google Drive, use the following wget command in your terminal:

wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O FILENAME

Replace the FILEID with the file id from the download URL. Also, replace FILENAME with the name of the file that you are downloading from Google Drive.

Downloading large files using WGET (over 100MB)

To download a large file stored on Google Drive, use the following wget command in your terminal:

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=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt

Replace the FILEID with the file id from the download URL. Also, replace FILENAME with the name of the file that you are downloading from Google Drive.

Alternatively, if you’re using Google Chrome as your web browser, there’s an extension called CurlWGET  that can help you generating any wget download command with a simple click.

That’s it! Now you know to download files stored on Google Drive using WGET in your terminal.