用命令行 从Google Drive下载文件

本文介绍了如何从Google Drive下载大文件,包括使用wget和curl命令行工具下载公开分享的小文件,以及通过Google API和OAuth token下载超过10GB或私密分享的大文件。详细步骤包括获取文件ID、OAuth令牌以及执行下载命令。
摘要由CSDN通过智能技术生成

参考:
<40M 文件 且是 公开分享:
用wget:
https://lccurious.github.io/2021/05/15/Download-from-Google-Drive/

<10G 且是 公开分享:
curl:
https://github.com/JinhangZhu/yolov3/blob/custom/data/get_coco2014.sh


  
# cd scratch place
cd scratch/
  
# Download zip dataset from Google Drive
filename='OfficeHomeDataset_10072016.zip'
fileid='0B81rNlvomiwed0V1YUxQdC1uOTg'
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}
rm ./cookie
  
# Unzip
#unzip -q ${filename}
#rm ${filename}
  
# cd out
cd

>10G 或者是 私密分享:
上面的方法会出现找不到文件的情况,用Google的官方API和认证token可以解决:
https://www.pianshen.com/article/8221279796/
或者查看英文原版问题答案:

以下答案来自:https://www.quora.com/How-do-I-download-a-very-large-file-from-Google-Drive

Get the file ID:
Go to your Google Drive in your browser.
Right-click (or control-click) the file you want to download and click “Get shareable link”. The link looks like this: https://drive.google.com/open?id=XXXXX. Make note of the file ID “XXXXX”; you will be needing it below.

Get an OAuth token:
Go to OAuth 2.0 Playground
In the “Select the Scope” box, scroll down, expand “Drive API v3”, and select https://www.googleapis.com/auth/drive.readonly
Click “Authorize APIs” and then “Exchange authorization code for tokens”. Copy the “Access token”; you will be needing it below.

Download the file from the command line:
curl -H “Authorization: Bearer YYYYY” https://www.googleapis.com/drive/v3/files/XXXXX?alt=media -o ZZZZZ

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值