How to download a Google Drive url via curl or wget How to download a Google Drive url via curl or wget curl curl

How to download a Google Drive url via curl or wget


How about this method? When the file is such large size, Google returns a code for downloading the file. You can download the file using the code. When such large file is downloaded using curl, you can see the code as follows.

<a id="uc-download-link" class="goog-inline-block jfk-button jfk-button-action" href="/uc?export=download&confirm=ABCD&id=### file ID ###">download</a>

The query with confirm=ABCD is important for downloading the file. This code is also included in the cookie. At the cookie, you can see it as follows.

#HttpOnly_.drive.google.com TRUE    /uc TRUE    #####   download_warning_#####  ABCD

In this case, "ABCD" is the code. In order to retrieve the code from the cookie and download the file, you can use the following script.

Sample script :

#!/bin/bashfileid="### file id ###"filename="MyFile.csv"curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/nullcurl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}

If this was not useful for you, I'm sorry.


Simplest and best way (with a real Google Drive file example)

  1. Install gdown using pip

    • Command - pip install gdown
  2. Let's say I wish to download cnn_stories.tgz from Google Drive

    • Download Link: https://drive.google.com/uc?export=download&id=0BwmD_VLjROrfTHk4NFg2SndKcjQ
  3. Please note the id URL parameter 0BwmD_VLjROrfTHk4NFg2SndKcjQ in the link

  4. That's it! Download the file using gdown

    • gdown --id 0BwmD_VLjROrfTHk4NFg2SndKcjQ --output cnn_stories.tgz


TLDR: gdown --id {gdrive_file_id} --output {file_name}


Command Line Args:

--id : Google drive file ID

--output: Output File name


You need to use the -L switch to make curl follow redirects, and the correct switch for the filename is -o. You should also quote the URL:

 curl -L -o myfile.xls "https://drive.google.com/uc?export=download&id=0B4fk8L6brI_eX1U5Ui1Lb1FpVG8"