1 words - 1 min read.

If you need to download a large (> 40 mB) file off of Google Drive via wget or curl you're going to have a bad time. Google Drive likes to scan files for viruses before allowing you to download them but it doesn't bother if the file is over 40 mB. Instead it will present you with a prompt that warns you that the file was too large to scan and may be a risk.


The download button contains a generated code that changes frequently (I have no idea how often) and that token must be provided as part of the query to download the file. I wrote a script that grabs the HTML of the warning page via curl, scrapes the code out via a perl regex (couldn't use sed because I needed lazy/reluctant matching and sed doesn't provide that), and constructs a valid url.

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`
curl -b ./cookie.txt -L -o ${filename} $url

I've seen this code elsewhere, but it's usually a bit more complicated and required you to download other tools like pup for parsing the HTML.

© 2019. All Rights Reserved.

Proudly published with Ghost