60

I want to download a folder from my google drive using terminal? Is there any way to do that? I tried this:

$ wget "https://drive.google.com/folderview?id=0B-Zc9K0k9q-WWUlqMXAyTG40MjA&usp=sharing"

But it is downloading this text file: folderview?id=0B-Zc9K0k9q-WdEY5a1BCUDBaejQ&usp=sharing. Is there any way to download google drive folder from terminal?

  • 1
    Check Mount Google Drive in Linux?. – henrique Jun 10 '14 at 12:11
  • I have checked them but they can't handle google spreadsheet. As I need access to spreadsheet and ocamlfuse can handle this, I thought of downloading them everytime I need them though time comsuming with respect to mount. But I have no other options. – user22180 Jun 10 '14 at 12:36
  • Set the folder setting to "anyone on the internet can find and view", then you will be able to download the file with wget https://googledrive.com/host/file_id for you that is wget https://googledrive.com/host/0B-Zc9K0k9q-WdEY5a1BCUDBaejQ. Solution explained here in more details. – Paul Rougieux May 11 '16 at 12:30
  • Any new answers for this during the time passed? we have one option below. – Matan Jan 21 '18 at 19:23
49

I was able to download a public shared file using this command:

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

Where FILEID must be replaced by the actual file ID. FILENAME is the path/filename where download will be stored.

Note you cannot use a folderid instead of fileid. I have used view source in a folder view where I could find the following HTML <div id="entry-0B0jxxycBojSwVW.... The string starting with 0B was the fileid.

  • 4
    This worked great for me! just had to use drive.google.com instead – thouliha Jun 11 '15 at 14:36
  • since I had a large file I kept getting the google virus scanner warning (that it can't scan). I did not find a solution for this problem. However, I realized that I could simply use scp to transfer the file to my server (which had the need for such downloading) – Matthias Sep 9 '16 at 16:56
  • 2
    this is not working anymore with google drive... – loretoparisi Apr 10 '17 at 0:00
  • 2
    This won't work for larger files. This answer in stack overflow works like a charm : stackoverflow.com/a/32742700/4773609 – H G Sur May 4 '17 at 7:42
  • 1
    @HGSur My answer below also works for large files. – FrankerZ Jun 25 '18 at 21:09
23

For google drive files that are too big, and you get a "Google cannot provide a virus-scan" error message, here is the solution I used:

First, attempt to download the file here (follow the steps above):

$ wget --save-cookies 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_]+).*/Code: \1\n/p'

Next, after we get the code (It will be output to the webpage, and output using sed above), use the following URL:

$ wget --load-cookies cookies.txt 'https://docs.google.com/uc?export=download&confirm=CODE_FROM_ABOVE&id=FILEID'

Add -O FILENAME to the previous wget statement to specify a filename, if you want to write it to a file.

  • This works like a charm! If you add --content-disposition wget will give the file the correct name automatically – Waleed Hamra Jul 22 at 15:52
8

A newer, open-source multi-platform client, written in Go called drive is quite nice and full-featured, and also is in active development.

Examples

The pull command downloads data from Google Drive that does not exist locally, and deletes local data that is not present on Google Drive. Run it without any arguments to pull all of the files from the current path:

$ drive pull

Pulling by matches is also supported

$ cd ~/myDrive/content/2015
$ drive pull --matches vines docx

See the above link for further examples, these are just the tip of the iceberg.

  • 1
    This tool is not maintained since September 2017 – Mateusz Konieczny Nov 1 '18 at 11:30
  • Yes but it still works and to download a whole directory it's the best solution: drive pull 'Colab Notebooks/sorted/models/resnet-101-90.9-max-acc'. The other methods are a pain in the ass. – Avio Aug 9 at 9:49
7

wget can only handle direct links, but that is not the main problem here. Google Drive expects you to authenticate before downloading your file. This means you will have to use a web browser to download the file. There are a few web browsers for the terminal, lynx is an example.

If you choose to publicly share your file (so that anyone can download it) you can use one of the numerous Google Drive permalink services. I believe these should produce links that will work with wget. Here is a list of two I found when searching for information: http://gdriveurl.com/ http://gdurl.com/

Assuming you are running Linux there is an open source client for Google Drive that might be worth looking into.

  • lynx is showing "redirecting" for more than 5 minutes when trying to access the drive. "Google Drive permalink" is ok, but I don't want to share it with everyone. I have used Grive and Ocamlfuse but they can't access spreadsheets – user22180 Jun 10 '14 at 10:37
  • Confirmed the "download" link from gdriveurl worked with wget – Randall Mar 24 '16 at 21:38
  • regarding the open source client suggestion: from my experience using that gdrive client and a similar utility called rclone, I have had better experiences with rclone. – 7yl4r Jun 23 '17 at 17:10
7

There is a giant program in the ubuntu 17.04 repository called: rclone

$ sudo apt update && sudo apt install rclone

$ rclone config --> than follow the steps to setup your gdrive

now you can rclone copy and sync everything you want. The projects supports all kinds of clouds.. f.e.:

$ rclone sync /home/<usrname>/Desktop/yourfolder gdrivename:yourfolder

[1]: https://rclone.org

(btw I uploaded about 600GB and transferred 1TB with rclone from gdrive to gdrive in few hours, gdrive to ubuntu and ubuntu to gdrive.. and it works terrific over weeks in a row!!

https://forum.rclone.org/t/can-copy-between-google-drive-accounts-without-download-and-upload-files/969/8

)

5

you can try, if you are on firefox, installing cliget addon. For every file that you want to download program show you curl, wget or aria2 direct link for downloading that file. I use that to download files on other machines via ssh because it's much faster for me to download directly to remote computer then to upload that file from my computer. This also work with dropbox, gdrive etc.

5

You can use the open source Linux / Unix command line tool gdrive.

To install it:

  1. Download the binary. Choose the one that fits your architecture, for example gdrive-linux-x64.

  2. Copy it to your path.

    sudo cp gdrive-linux-x64 /usr/local/bin/gdrive;
    sudo chmod a+x /usr/local/bin/gdrive;
    

To use it:

  1. Determine the Google Drive folder's ID. For that, go inside the folder to download, using the drive.google.com web client. Now look at the URL in the browser's address bar, it will show something like https://drive.google.com/drive/folders/0B7_OwkDsUIgFWXA1B2FPQfV5S8H. Obtain the string behind the last / and copy it to your clipboard. That's the folder's ID.

  2. Download the folder. Of course, use your folder's ID instead in the following command.

    gdrive download --recursive 0B7_OwkDsUIgFWXA1B2FPQfV5S8H
    

At first usage, the tool will need to obtain access permissions to the Google Drive API. For that, it will show you a link which you have to visit in a browser, and then you will get a verification code to copy&paste back to the tool. The download then starts automatically. There is no progress indicator, but you can observe the progress in a file manager or second terminal.

Source: A comment by Tobi in a stackoverflow.com question. Answer adapted from my similar answer over there.

  • Can't get permission? Sign in with Google temporarily disabled for this app This app has not been verified yet by Google in order to use Google Sign In. – unami Dec 7 at 23:49
4

Download binary from the below link

chmod +x <binary>
./drive download id

It will generate link for verification code. Click the link and allow access to gdrive and copy the verification code from browser. Paste it.

It works for me

Not the answer you're looking for? Browse other questions tagged or ask your own question.