Is there a way to download a publicly-viewable Google Drive url via curl or wget? For example, being able to do something like:
curl -O myfile.xls https://drive.google.com/uc?export=download&id=1Wb2NfKTQr_dLoFJH0GfM0cx-t4r07IVl
Note, I'm looking to do this on a publicly-viewable file without having to sign into my Google account (or have someone else sign into their account, etc.).
If helpful, the cors headers I have are:
"kind": "drive#file", "id": "1Wb2NfKTQr_dLoFJH0GfM0cx-t4r07IVl",
Right-click on the file you want to download, click share, under link sharing section, select "anyone with this link can edit". Copy the FILEIDENTIFIER portion from the link. Copy the below script to a file. It uses curl and processes the cookie to automate the downloading of the file.
Grab file with curl run: $ curl https://your-domain/file.pdf. Get file using ftp or sftp protocol: $ curl ftp://ftp-your-domain-name/file.tar.gz. You can set the output file name while downloading file with the curl, execute: $ curl -o file. pdf https://your-domain-name/long-file-name.pdf.
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.
#!/bin/bash fileid="### file id ###" filename="MyFile.csv" curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null curl -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.
Recently, it seems that the specification of this flow has been changed. So I updated this answer. In order to download a publicly shared file of large size from Google Drive, you can use the following script.
#!/bin/bash fileid="### file id ###" filename="MyFile.csv" html=`curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}"` curl -Lb ./cookie "https://drive.google.com/uc?export=download&`echo ${html}|grep -Po '(confirm=[a-zA-Z0-9\-_]+)'`&id=${fileid}" -o ${filename}
In this case, the ID for downloading is retrieved from the HTML data as follows.
<form id="downloadForm" action="https://drive.google.com/uc?export=download&id={fileId}&confirm={value for downloading}" method="post">
When you want to download a publicly shared file of small size from Google Drive, you can use the following command.
curl -L "https://drive.google.com/uc?export=download&id=### fileId ###" -o sampleoutput.csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With