Skip to content

Instantly share code, notes, and snippets.

@jbdemonte
Created August 30, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbdemonte/dea5c9cd8433030bdd3a7a9d56c8639f to your computer and use it in GitHub Desktop.
Save jbdemonte/dea5c9cd8433030bdd3a7a9d56c8639f to your computer and use it in GitHub Desktop.
Google Drive large file download script using curl
#!/bin/bash
# Based on http://blog.mclain.ca/download-large-files-from-google-drive-via-curl/
# Usage: ./curl-download.sh file_id
file_id=$1
if [[ -z "$file_id" ]]; then
echo "ERROR - file_id is missing"
echo " Usage: ./curl-download.sh file_id"
exit 1
fi
echo "" > ./cookie.txt
echo "accessing ${file_id}"
filename=`curl -c ./cookie.txt -s -L "https://drive.google.com/uc?export=download&id=${file_id}" \
| perl -nE'say/uc-name-size.*? href=".*?\">(.*?)</' \
| sed -e 's/amp;//g' | sed -n 2p`
if [[ -z "$filename" ]]; then
echo "ERROR - filename is missing"
exit 2
fi
query=`curl -c ./cookie.txt -s -L "https://drive.google.com/uc?export=download&id=${file_id}" \
| perl -nE'say/uc-download-link.*? href="(.*?)\">/' \
| sed -e 's/amp;//g' | sed -n 2p`
url="https://drive.google.com$query"
echo "Downloading ${filename}"
curl -b ./cookie.txt -L -o "${filename}" $url && echo "${filename} downloaded"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment