How to download a google drive folder using link in linux

31.4k views Asked by At

I have a shared google drive folder link(Anyone on the internet with this link can view) as below Ex: https://drive.google.com/drive/folders/1i_c8LhSLf-LttV-UOMDcY4rLAalxxxx?usp=sharing

I want to download using any of the wget/CURL/any python packages.

I have tried the below and it doesn't work.

 curl -L "https://drive.google.com/uc?id=1i_c8LhSLf-LttV-UOMDcY4rLAalkcayn&export=download" > test.tar.gz
import gdown
import time
url='https://drive.google.com/uc?id=1i_c8LhSLf-LttV-UOMDcY4rLAalkxxxx'
output='/data/test/test.zip'
time.sleep(100)
gdown.download(url, output, quiet=False)

Error:

Permission denied: https://drive.google.com/uc?id=1i_c8LhSLf-LttV-UOMDcY4rLAalkcayn
Maybe you need to change permission over 'Anyone with the link'?

The below command worked for files but not for folders

wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=11e85AnMEGEjrxPuewlmeg-ABOZ8asdf' -O test

Thanks for your help in advance!

1

There are 1 answers

4
SolomidHero On

Update:

Now folder download functional is in main gdown package, so simply do the following

  1. install via pip
pip install gdown
  1. use it in python:
import gdown
gdown.download_folder(url, quiet=True)

Using "gdown"

gdown is a great application to download single file from gdrive with only file id or link required, but there were several great minds of github who were inspired to implement a folder download functionality.

Actually, state of this feature can be viewed in gdown:90 github PR.

You can use it, since it is implemented almost perfectly (there is an issue of only 50 files in folder as maximum to download):

  1. install gdown with developed folder_download feature via pip:
pip install git+https://github.com/giuliano-oliveira/gdown_folder.git
  1. Now we need to run gdown.download_folder function in python3 shell (since cli support for folder download is not implemented):

$ python3

import gdown
gdown.download_folder(gdrive_folder_link, quiet=True)

Use your own gdrive_folder_link in string format 'https://drive.google.com/drive/u/1/folders/{id}' (others weren't checked).

Note:

  • You might be required to signup to gdown application.
  • Also, remember about maximum downloaded elements from folder is 50, since there is internal problems with acquiring relevant information about all items via gdrive request API.
  • You might be required to create the target folder name