Skip to content

Instantly share code, notes, and snippets.

@amit-chahar
Last active February 20, 2023 12:57
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save amit-chahar/db49ce64f46367325293e4cce13d2424 to your computer and use it in GitHub Desktop.
Save amit-chahar/db49ce64f46367325293e4cce13d2424 to your computer and use it in GitHub Desktop.
Scirpt to download files from Google drive using curl (Detailed explanation can be read here: https://stackoverflow.com/a/49444877/4043524)
#!/bin/bash
fileid="FILEIDENTIFIER"
filename="FILENAME"
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}
@acurrieclark
Copy link

Many thanks for this handy script

@Sar777
Copy link

Sar777 commented Apr 22, 2018

thx

@o6a-ha
Copy link

o6a-ha commented Jul 6, 2018

Thank you!

@dehuachen
Copy link

Thank you!
and I made a small change:

#!/bin/bash
fileid="$1"
filename="$2"
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}

remove cookie

you can run it like:

bash download_script.sh <fileid> <filename>

@castaway2000
Copy link

For anyone who stumbles on this thread the following works as of May 2022 to get around the antivirus check:

#!/bin/bash
fileid="FILEIDENTIFIER"
filename="FILENAME"
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}

@arcc-ve
Copy link

arcc-ve commented Feb 20, 2023

For anyone who stumbles on this thread the following works as of May 2022 to get around the antivirus check:

#!/bin/bash
fileid="FILEIDENTIFIER"
filename="FILENAME"
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}

Thank you very much for this practical and amazing script

Note: At the moment it is not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment