我试图在脚本中从google云端硬盘下载文件,并且这样做有点麻烦。我试图下载的文件是 这里.

我在网上看了很多,我终于设法让其中一个下载。我得到了文件的Uid,较小的一个(1.6MB)下载正常,但是较大的文件(3.7GB)总是重定向到一个页面,询问我是否要在没有病毒扫描的情况下继续下载。有人能帮我通过屏幕吗?

以下是我如何让第一个文件工作 -

curl -L "https://docs.google.com/uc?export=download&id=0Bz-w5tutuZIYeDU0VDRFWG9IVUE" > phlat-1.0.tar.gz

当我在另一个文件上运行相同,

curl -L "https://docs.google.com/uc?export=download&id=0Bz-w5tutuZIYY3h5YlMzTjhnbGM" > index4phlat.tar.gz

我得到以下输出 - enter image description here

我注意到在链接的第三到最后一行,有一个 &confirm=JwkK 这是一个随机的4个字符串,但建议有一种方法可以向我的URL添加确认。我访问过的一个链接建议 &confirm=no_antivirus 但这是行不通的。

我希望有人在这里可以帮助这个!

先谢谢你。

有帮助吗?

解决方案

看看这个问题:直接从谷歌下载使用Google Drive API驱动

基本上您必须创建一个公共目录并通过相对引用使用

等类似的文件来访问您的文件
wget https://googledrive.com/host/LARGEPUBLICFOLDERID/index4phlat.tar.gz
.

警告:此功能已不推荐使用。在评论中,请参阅下面的警告。

或者,您可以使用此脚本: https://github.com/circulosmeos/gdown.pl

其他提示

我写了一个python代码段,下载Google Drive的文件,给定可共享链接。它有效,截至2017年8月

剪辑不使用 GDrive ,也不使用Google Drive API。它使用请求模块。

从Google Drive下载大文件时,单个Get请求不足以。需要第二个,并且这个具有额外的URL参数,称为确认,其值应等于某个cookie的值。

import requests

def download_file_from_google_drive(id, destination):
    def get_confirm_token(response):
        for key, value in response.cookies.items():
            if key.startswith('download_warning'):
                return value

        return None

    def save_response_content(response, destination):
        CHUNK_SIZE = 32768

        with open(destination, "wb") as f:
            for chunk in response.iter_content(CHUNK_SIZE):
                if chunk: # filter out keep-alive new chunks
                    f.write(chunk)

    URL = "https://docs.google.com/uc?export=download"

    session = requests.Session()

    response = session.get(URL, params = { 'id' : id }, stream = True)
    token = get_confirm_token(response)

    if token:
        params = { 'id' : id, 'confirm' : token }
        response = session.get(URL, params = params, stream = True)

    save_response_content(response, destination)    


if __name__ == "__main__":
    import sys
    if len(sys.argv) is not 3:
        print("Usage: python google_drive.py drive_file_id destination_file_path")
    else:
        # TAKE ID FROM SHAREABLE LINK
        file_id = sys.argv[1]
        # DESTINATION FILE ON YOUR DISK
        destination = sys.argv[2]
        download_file_from_google_drive(file_id, destination)
.

2019年9月

file_id应该看起来像0bz8a_dbh9qhbnu3sglfadg

您可以通过右键单击该文件,然后获得可共享链接。 仅在开放访问文件中工作。 不适用于目录。 在谷歌Colab上测试。

示例:从此目录

gdown https://drive.google.com/uc?id=0B7EVK8r0v71pOXBhSUdJWU1MYUk
.

您可以使用开源Linux/Unix命令行工具 gdrive.

要安装它:

  1. 下载 的二进制文件。 例如,选择适合您架构的架构 gdrive-linux-x64.

  2. 将其复制到您的路径。

    sudo cp gdrive-linux-x64 /usr/local/bin/gdrive;
    sudo chmod a+x /usr/local/bin/gdrive;
    

使用它:

  1. 确定Google云端硬盘文件ID。 为此,在Google云端硬盘网站中右键单击所需的文件,然后选择"获取链接..."。它会返回类似的东西 https://drive.google.com/open?id=0B7_OwkDsUIgFWXA1B2FPQfV5S8H.获取后面的字符串 ?id= 并将其复制到剪贴板。这是文件的ID。

  2. 下载文件。 当然,在下面的命令中使用文件的ID。

    gdrive download 0B7_OwkDsUIgFWXA1B2FPQfV5S8H
    

首次使用时,该工具需要获得Google Drive API的访问权限。为此,它会向您显示一个链接,您必须在浏览器中访问该链接,然后您将获得一个验证码以复制并粘贴回该工具。然后自动开始下载。没有进度指示器,但您可以在文件管理器或第二个终端中观察进度。

资料来源: 托比的评论 在这里的另一个答案。

 

额外技巧:速率限制。 下载 gdrive 在有限的最大速率(不淹没网络...),你可以使用这样的命令(pv琵琶手):

gdrive download --stdout 0B7_OwkDsUIgFWXA1B2FPQfV5S8H | \
  pv -br -L 90k | \
  cat > file.ext

这将显示下载的数据量(-b)和下载速率(-r)并将该速率限制在90kiB/s(-L 90k).

ggID='put_googleID_here'  
ggURL='https://drive.google.com/uc?export=download'  
filename="$(curl -sc /tmp/gcokie "${ggURL}&id=${ggID}" | grep -o '="uc-name.*</span>' | sed 's/.*">//;s/<.a> .*//')"  
getcode="$(awk '/_warning_/ {print $NF}' /tmp/gcokie)"  
curl -Lb /tmp/gcokie "${ggURL}&confirm=${getcode}&id=${ggID}" -o "${filename}"  
.

它是如何工作的?
使用curl获取cookie文件和html代码。
将HTML管道和SED和SED搜索文件名。
使用awk获取cookie文件的确认代码。
最后将文件下载到启用cookie,确认代码和文件名。

curl -Lb /tmp/gcokie "https://drive.google.com/uc?export=download&confirm=Uq6r&id=0B5IRsLTwEO6CVXFURmpQZ1Jxc0U" -o "SomeBigFile.zip"
.


如果您不需要Filename变量卷曲可以猜测它


-L跟随重定向 -O remote-name
-j远程头名称

curl -sc /tmp/gcokie "${ggURL}&id=${ggID}" >/dev/null  
getcode="$(awk '/_warning_/ {print $NF}' /tmp/gcokie)"  
curl -LOJb /tmp/gcokie "${ggURL}&confirm=${getcode}&id=${ggID}" 
.


从您可以使用的URL中提取Google文件ID:

echo "gURL" | egrep -o '(\w|-){26,}'  
# match more than 26 word characters  
.

echo "gURL" | sed 's/[^A-Za-z0-9_-]/\n/g' | sed -rn '/.{26}/p'  
# replace non-word characters with new line,   
# print only line with more than 26 word characters 
.

更新至2018年3月。

我尝试了其他答案中给出的各种技术,将我的文件(6GB)直接从Google云端硬盘下载到我的AWS ec2实例,但它们都不起作用(可能是因为它们很旧)。

所以,对于其他人的信息,这里是我如何成功地做到这一点:

  1. 右键单击要下载的文件,单击共享,在链接共享部分下,选择"任何拥有此链接的人都可以编辑"。
  2. 复制链接。它应该是这种格式: https://drive.google.com/file/d/FILEIDENTIFIER/view?usp=sharing
  3. 从链接复制FILEIDENTIFIER部分。
  4. 将下面的脚本复制到文件中。它使用curl并处理cookie来自动下载文件。

    #!/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}
    
  5. 如上所示,将FILEIDENTIFIER粘贴到脚本中。记得保持双引号!

  6. 为文件提供一个名称来代替文件名。请记住保留双引号,并在文件名中包含扩展名(例如, myfile.zip).
  7. 现在,保存文件并通过在终端中运行此命令使文件可执行 sudo chmod +x download-gdrive.sh.
  8. 使用`./运行脚本download-gdrive.sh"。

PS:下面是上面给定脚本的Github要点: https://gist.github.com/amit-chahar/db49ce64f46367325293e4cce13d2424

这是一种快速的方法来做这件事。

确保链接共享,它将看起来像这样:

https://drive.google.com/open?id=filed& authuser=0

然后,将该文件复制并使用它如此

wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O FILENAME
.

Google Drive的默认行为是扫描病毒的文件,如果该文件大于它将提示用户并通知他无法扫描该文件。

目前我发现的唯一解决方法是使用Web共享文件并创建Web资源。

从Google Drive帮助页面中报价:

使用驱动器,您可以制作Web资源 - 类似HTML,CSS和JavaScript文件 - 浏览为网站。

使用驱动器托管网页:

  1. 在drive.google.com上打开驱动器并选择文件。
  2. 单击页面顶部的 share 按钮。
  3. 单击共享框右下角的高级
  4. 单击更改....
  5. 在web上选择 On-Public ,然后单击保存
  6. 在关闭共享框之前,将文档ID从“链接以分享”的字段中的URL中复制。文档ID是一串大写和小写字母,在URL中的斜杠之间的数字。
  7. 共享看起来像“www.googledrive.com/host/[ddoc id”的URL,其中在步骤6中复制的文档ID替换了[doc id] 任何人现在都可以查看您的网页。

在这里找到: https://support.google.com/drive/answer / 2881970?HL= en

所以例如,当您公开在Google驱动器上共享文件时,Sharelink看起来如此:

https://drive.google.com/file/d/0B5IRsLTwEO6CVXFURmpQZ1Jxc0U/view?usp=sharing
. 然后,您复制文件ID并创建一个看起来像这样的googledrive.com linke:

https://www.googledrive.com/host/0B5IRsLTwEO6CVXFURmpQZ1Jxc0U
.

简单的方法:

(如果您只需要一次性下载)

  1. 转到具有下载链接的Google云端硬盘网页
  2. 打开浏览器控制台并转到"网络"选项卡
  3. 点击下载链接
  4. 等待它的文件开始下载,并找到相应的请求(应该是列表中的最后一个),然后你可以取消下载
  5. 右键单击请求并单击"复制为cURL"(或类似)

你最终应该得到类似的东西:

curl 'https://doc-0s-80-docs.googleusercontent.com/docs/securesc/aa51s66fhf9273i....................blah blah blah...............gEIqZ3KAQ==' --compressed

过去它在您的控制台中,添加 > my-file-name.extension 到最后(否则它会将文件写入您的控制台),然后按enter:)

基于Roshan Sethia的答案

2018年5月

使用 wget

  1. 创建一个名为wgetgdrive.sh的shell脚本如下:

    #!/bin/bash
    
    # Get files from Google Drive
    
    # $1 = file ID
    # $2 = file name
    
    URL="https://docs.google.com/uc?export=download&id=$1"
    
    wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate $URL -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=$1" -O $2 && rm -rf /tmp/cookies.txt
    
  2. 给出执行脚本

  3. 的正确权限 终端中

  4. ,运行:

    ./wgetgdrive.sh <file ID> <filename>
    
    .

    例如:

    ./wgetgdrive.sh 1lsDPURlTNzS62xEOAIG98gsaW6x2PYd2 images.zip
    

--更新--

要下载文件首先得到 youtube-dl 对于python从这里:

youtube-dl: https://rg3.github.io/youtube-dl/download.html

或安装它与 pip:

sudo python2.7 -m pip install --upgrade youtube_dl 
# or 
# sudo python3.6 -m pip install --upgrade youtube_dl

更新资料:

我刚发现这个:

  1. 右键单击要从中下载的文件drive.google.com

  2. 点击 Get Sharable link

  3. 打开/打开 Link sharing on

  4. 点击 Sharing settings

  5. 点击顶部的下拉选项

  6. 点击更多

  7. 选择 [x] On - Anyone with a link

  8. 复制连结

https://drive.google.com/file/d/3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR/view?usp=sharing       
(This is not a real file address)

复制id后 https://drive.google.com/file/d/:

3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR

将其粘贴到命令行中:

youtube-dl https://drive.google.com/open?id=

将id粘贴到后面 open?id=

youtube-dl https://drive.google.com/open?id=3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR
[GoogleDrive] 3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR: Downloading webpage
[GoogleDrive] 3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR: Requesting source file
[download] Destination: your_requested_filename_here-3PIY9dCoWRs-930HHvY-3-FOOPrIVoBAR
[download] 240.37MiB at  2321.53MiB/s (00:01)

希望有帮助

没有答案提出什么对我有用 2016年12月 (资料来源):

curl -L https://drive.google.com/uc?id={FileID}

只要谷歌驱动器文件已与那些有链接和共享 {FileID} 是后面的字符串 ?id= 在共享的URL中。

虽然我没有检查巨大的文件,我相信它可能是有用的知道。

我对Google Drive有同样的问题。

这是我如何使用链接2 解决问题的方式。

  1. 在PC上打开浏览器,在Google Drive中导航到您的文件。为您的文件提供公共链接。

  2. 将公共链接复制到剪贴板(例如,右键单击,复制链接地址)

  3. 打开终端。如果您正在下载到另一个PC / Server / Machine,则应将其SSH作为此点

  4. 安装链接2(debian / ubuntu方法,使用您的发行版或OS等效应)

    sudo apt-get install links2

  5. 将链接粘贴到终端中,并使用如此:

    的链接打开它

    links2 "paste url here"

  6. 使用箭头键在链接中导航到下载链接,然后按输入

  7. 选择一个文件名,它会下载文件

最简单的方法是:

  1. create 下载链接和复制fileid
  2. 用wget下载:wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt

使用方法 youtube-dl!

youtube-dl https://drive.google.com/open?id=ABCDEFG1234567890

你也可以通过 --get-url 以获得直接下载URL。

有一个开源的多平台客户端,用go写入: drive 。它非常好,全功能,也在积极发展。

$ drive help pull
Name
        pull - pulls remote changes from Google Drive
Description
        Downloads content from the remote drive or modifies
         local content to match that on your Google Drive

Note: You can skip checksum verification by passing in flag `-ignore-checksum`

* For usage flags: `drive pull -h`
.

从Google驱动器向下文件的简单方法您还可以在Colab上下载文件

pip install gdown

import gdown
.

然后

url = 'https://drive.google.com/uc?id=0B9P1L--7Wd2vU3VUVlFnbTgtS2c'
output = 'spam.txt'
gdown.download(url, output, quiet=False)
.

fileid='0B9P1L7Wd2vU3VUVlFnbTgtS2c'

gdown https://drive.google.com/uc?id=+fileid
.

文档 https://pypi.org/project/gdown/

此处是解决方法,我提出了从谷歌驱动器下载到我的Google Cloud Linux shell的文件。

  1. 使用高级共享与“公共文件”和“编辑权限”共享文件。
  2. 您将获得一个具有ID的共享链接。查看链接: - drive.google.com/file/d/ [id] / view?usp= sharing
  3. 复制该ID并将其粘贴在以下链接中: -
  4. googledrive.com/host/ [id]

    1. 上面的链接将是我们的下载链接。
    2. 使用WGET下载文件: -
    3. wget https://googledrive.com/host/[id]

      1. 此命令将使用名称下载文件作为[id],没有扩展名,但在您运行wget命令的同一位置上的文件大小相同。
      2. 实际上,我在我的练习中下载了一个压缩文件夹。所以我使用: - 更名为此尴尬的文件

        mv [id] 1.zip

          然后使用

          解压缩1.zip

          我们将获取文件。

我无法获得nanoix的perl脚本来工作,或者我所看到的其他卷曲例子,所以我开始在Python中查看API。这对小文件进行了很好的工作,但大文件扼杀了可用的RAM,所以我找到了一些其他漂亮的块代码,它使用API部分下载的能力。gist在这里: https://gist.github.com/csik/c4c90987224150e4a0b2

注意从API接口下载Client_secret JSON文件到本地目录的比特。

source
$ cat gdrive_dl.py
from pydrive.auth import GoogleAuth  
from pydrive.drive import GoogleDrive    

"""API calls to download a very large google drive file.  The drive API only allows downloading to ram 
   (unlike, say, the Requests library's streaming option) so the files has to be partially downloaded
   and chunked.  Authentication requires a google api key, and a local download of client_secrets.json
   Thanks to Radek for the key functions: http://stackoverflow.com/questions/27617258/memoryerror-how-to-download-large-file-via-google-drive-sdk-using-python
"""

def partial(total_byte_len, part_size_limit):
    s = []
    for p in range(0, total_byte_len, part_size_limit):
        last = min(total_byte_len - 1, p + part_size_limit - 1)
        s.append([p, last])
    return s

def GD_download_file(service, file_id):
  drive_file = service.files().get(fileId=file_id).execute()
  download_url = drive_file.get('downloadUrl')
  total_size = int(drive_file.get('fileSize'))
  s = partial(total_size, 100000000) # I'm downloading BIG files, so 100M chunk size is fine for me
  title = drive_file.get('title')
  originalFilename = drive_file.get('originalFilename')
  filename = './' + originalFilename
  if download_url:
      with open(filename, 'wb') as file:
        print "Bytes downloaded: "
        for bytes in s:
          headers = {"Range" : 'bytes=%s-%s' % (bytes[0], bytes[1])}
          resp, content = service._http.request(download_url, headers=headers)
          if resp.status == 206 :
                file.write(content)
                file.flush()
          else:
            print 'An error occurred: %s' % resp
            return None
          print str(bytes[1])+"..."
      return title, filename
  else:
    return None          


gauth = GoogleAuth()
gauth.CommandLineAuth() #requires cut and paste from a browser 

FILE_ID = 'SOMEID' #FileID is the simple file hash, like 0B1NzlxZ5RpdKS0NOS0x0Ym9kR0U

drive = GoogleDrive(gauth)
service = gauth.service
#file = drive.CreateFile({'id':FILE_ID})    # Use this to get file metadata
GD_download_file(service, FILE_ID) 
.

这是我写的一点点Bash脚本,今天就作了这项工作。它适用于大文件,也可以恢复部分获取的文件。它需要两个参数,第一个是file_id,第二个是输出文件的名称。这里对先前答案的主要改进是它在大文件上工作,只需要常用的工具:Bash,Curl,TR,Grep,Du,Cut和MV。

#!/usr/bin/env bash
fileid="$1"
destination="$2"

# try to download the file
curl -c /tmp/cookie -L -o /tmp/probe.bin "https://drive.google.com/uc?export=download&id=${fileid}"
probeSize=`du -b /tmp/probe.bin | cut -f1`

# did we get a virus message?
# this will be the first line we get when trying to retrive a large file
bigFileSig='<!DOCTYPE html><html><head><title>Google Drive - Virus scan warning</title><meta http-equiv="content-type" content="text/html; charset=utf-8"/>'
sigSize=${#bigFileSig}

if (( probeSize <= sigSize )); then
  virusMessage=false
else
  firstBytes=$(head -c $sigSize /tmp/probe.bin)
  if [ "$firstBytes" = "$bigFileSig" ]; then
    virusMessage=true
  else
    virusMessage=false
  fi
fi

if [ "$virusMessage" = true ] ; then
  confirm=$(tr ';' '\n' </tmp/probe.bin | grep confirm)
  confirm=${confirm:8:4}
  curl -C - -b /tmp/cookie -L -o "$destination" "https://drive.google.com/uc?export=download&id=${fileid}&confirm=${confirm}"
else
  mv /tmp/probe.bin "$destination"
fi
.

这项工作截至2017年11月 https://gist.github.com/ppetraki/258ea8240041e19ab258a736781f06db

#!/bin/bash

SOURCE="$1"
if [ "${SOURCE}" == "" ]; then
    echo "Must specify a source url"
    exit 1
fi

DEST="$2"
if [ "${DEST}" == "" ]; then
    echo "Must specify a destination filename"
    exit 1
fi

FILEID=$(echo $SOURCE | rev | cut -d= -f1 | rev)
COOKIES=$(mktemp)

CODE=$(wget --save-cookies $COOKIES --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=${FILEID}" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/Code: \1\n/p')

# cleanup the code, format is 'Code: XXXX'
CODE=$(echo $CODE | rev | cut -d: -f1 | rev | xargs)

wget --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" -O $DEST

rm -f $COOKIES
.

在捣乱这些垃圾之后。我已经找到了一种方法,通过使用chrome-developer tools下载我的sweet文件。

  1. 在您的google文档选项卡上,Ctr+Shift+J(设置->开发人员工具)
  2. 切换到网络选项卡
  3. 在您的文档文件中,单击"下载"->下载为CSV,xlsx,。...
  4. 它会在"网络"控制台中向您显示请求 enter image description here

  5. 右键单击->复制->复制为Curl

  6. 你的Curl命令将是这样的,并添加 -o 创建导出的文件。 curl 'https://docs.google.com/spreadsheets/d/1Cjsryejgn29BDiInOrGZWvg/export?format=xlsx&id=1Cjsryejgn29BDiInOrGZWvg' -H 'authority: docs.google.com' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (X..... -o server.xlsx

解决了!

我发现了一个工作解决方案......只需使用以下

wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1HlzTR1-YVoBPlXo0gMFJ_xY4ogMnfzDi' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1HlzTR1-YVoBPlXo0gMFJ_xY4ogMnfzDi" -O besteyewear.zip && rm -rf /tmp/cookies.txt
.

2018年5月工作

嗨,基于此评论...我创建一个bash,可以从文件 urls.txt 从文件 urls_decoded.txt 导出一个URL列表 在Flashget这样的Accelerator中使用(我使用cygwin来组合Windows和Linux)

命令蜘蛛是避免下载并获得最终链接(直接)

命令grep头部和剪切,过程并获得最终链接,是以西班牙语为基础的,也许你可以是英语的端口

echo -e "$URL_TO_DOWNLOAD\r"可能是\ r是只有cywin,必须用\ n(中断线)

替换

**********user***********是用户文件夹

*******Localización***********是用西班牙语,清除音节,让字中的英语位置,并调整头部和切割数字来占用方法。

rm -rf /home/**********user***********/URLS_DECODED.txt
COUNTER=0
while read p; do 
    string=$p
    hash="${string#*id=}"
    hash="${hash%&*}"
    hash="${hash#*file/d/}"
    hash="${hash%/*}"
    let COUNTER=COUNTER+1
    echo "Enlace "$COUNTER" id="$hash
    URL_TO_DOWNLOAD=$(wget --spider --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='$hash -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id="$hash 2>&1 | grep *******Localización***********: | head -c-13 | cut -c16-)
    rm -rf /tmp/cookies.txt
    echo -e "$URL_TO_DOWNLOAD\r" >> /home/**********user***********/URLS_DECODED.txt
    echo "Enlace "$COUNTER" URL="$URL_TO_DOWNLOAD
done < /home/**********user***********/URLS.txt
.

您只需要使用WGET:

 https://drive.google.com/uc?authuser=0&id=[your ID without brackets]&export=download
.

pd。该文件必须是公共的。

There's an easier way.

Install cliget/CURLWGET from firefox/chrome extension.

Download the file from browser. This creates a curl/wget link that remembers the cookies and headers used while downloading the file. Use this command from any shell to download

I have been using the curl snippet of @Amit Chahar who posted a good answer in this thread. I found it useful to put it in a bash function rather than a separate .sh file

function curl_gdrive {

    GDRIVE_FILE_ID=$1
    DEST_PATH=$2

    curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${GDRIVE_FILE_ID}" > /dev/null
    curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${GDRIVE_FILE_ID}" -o ${DEST_PATH}
    rm -fr cookie
}

that can be included in e.g a ~/.bashrc (after sourcing it ofcourse if not sourced automatically) and used in the following way

   $ curl_gdrive 153bpzybhfqDspyO_gdbcG5CMlI19ASba imagenet.tar

skicka is a cli tool to upload,download access files from a google-drive.

example -

skicka download /Pictures/2014 ~/Pictures.copy/2014
10 / 10 [=====================================================] 100.00 % 
skicka: preparation time 1s, sync time 6s
skicka: updated 0 Drive files, 10 local files
skicka: 0 B read from disk, 16.18 MiB written to disk
skicka: 0 B uploaded (0 B/s), 16.18 MiB downloaded (2.33 MiB/s)
skicka: 50.23 MiB peak memory used

May 2018

If you want to use curl to download a file from Google Drive, in addition to the file id in drive you also need an OAuth2 access_token for Google Drive API. Getting the token involves several steps with the Google API framework. The sign up steps with Google are (currently) free.

An OAuth2 access_token potentially allows all kinds of activity, so be careful with it. Also, the token times out after a short while (1 hour?) but not short enough to prevent abuse if someone captures it.

Once you have an access_token and the fileid, this will work:

AUTH="Authorization: Bearer the_access_token_goes_here"
FILEID="fileid_goes_here"
URL=https://www.googleapis.com/drive/v3/files/$FILEID?alt=media
curl --header "$AUTH" $URL >myfile.ext

See also: Google Drive APIs -- REST -- Download Files

Get the shareable link and open it in incognito (very important). It will say that it cannot scan.

Open inspector and track network traffic. Click the button "Download anyway".

Copy the url of the last request made. This is your link. Use it in wget.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top