美文网首页
通过wget或curl命令行从 Google Drive下载数据

通过wget或curl命令行从 Google Drive下载数据

作者: 水他 | 来源:发表于2023-06-24 11:25 被阅读0次

本文介绍了通过wget和curl从Google Drive上下载文件的脚本。因为大量的数据集都存放在Google Drive上,而计算任务通常都是在计算服务器上,直接从Google Drive这类云盘下载到服务器上显然是最合适的方式。

分享链接

Google Drive的分享链接格式通常为:

https://drive.google.com/file/d/

其中这个<fileid>就是对应文件在服务器上的唯一标识符。

例如chinese_llama_plus_lora_7b.zip (756M) 模型权重在Google Drive上的链接即为:

https://drive.google.com/u/0/uc?id=1N97m3rBj-rp-J1X8rgRfluyomEscfAq0&export=download

其中的为1N97m3rBj-rp-J1X8rgRfluyomEscfAq0,文件名可以自己取。

所以提取到的关键变量为:

filename='chinese_llama_plus_lora_7b.zip'
fileid='1N97m3rBj-rp-J1X8rgRfluyomEscfAq0'

wget 下载指令

  • 针对小文件:

wget --no-check-certificate "https://drive.google.com/uc?export=download&id={fileid}" -O{filename}

  • 如果文件大的话,需要对cookie进行处理:

wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://drive.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

  • 整理成更方便的脚本示例为:
#!/bin/bash

# cd scratch place
cd data/

# Download zip dataset from Google Drive
filename='OfficeHomeDataset_10072016.zip'
fileid='0B81rNlvomiwed0V1YUxQdC1uOTg'
wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://drive.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

# Unzip
unzip -q ${filename}
rm ${filename}
cd

curl 下载指令

  • 小文件 < 40MB:

curl -L -o {filename} "https://drive.google.com/uc?export=download&id={fileid}"

  • 大文件 > 40MB:

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/ {printNF}' ./cookie`&id={fileid}" -o{filename} rm ./cookie

  • 整理成脚本:
#!/bin/bash
  
# 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

但是如果连不上外网,那就需要一个梯子的选项,即proxychains4这个命令行代理工具,或者需要通过其他机器进行联网的中转可以参考

对于不能直接联网的机器运行脚本方式为:

proxychains4 sh download_google_drive.sh

参考资源

相关文章

  • Google Drive使用 wget下载

    对于小文件 对于大文件,由于需要确认cookies等,所以需要对cookies进行操作。 这样就可以将文件下载到$...

  • curl 和 wget 有什么区别?

    主要区别在于: 与 curl 相比,wget 的主要优点是它能够递归下载。 wget 只是命令行。 curl 支持...

  • curl使用指南

    curl是一个命令行工具,通过指定的URL来上传或下载数据,并将数据展示出来。curl中的c表示client,而U...

  • shell脚本(5)一团乱麻?没这回事

    1、wget命令行下载工具 2、curl入门 作为一款强力工具,curl支持包括HTTP,HTTPS,FTP在内的...

  • linux命令之 curl

    前言 CURL是一个命令行工具,curl中的c表示client。用于通过指定URL来上传或者下载数据,并将数据展示...

  • curl 和 wget

    直接在 linux 命令行下载文件的两个工具 wget 和 curl curl在 web 请求方面以及协议 htt...

  • 2019-04-18

    1. data 的下载,data的完整性,data的打包 2. 下载数据 wget curl 3.wget --a...

  • Day5 文件管理(3)

    文件管理之:联网下载文件(wget、curl)、文件上传与下载(rz、sz) ----wget、curl联网下载文...

  • 一些比较好用的第三方package推荐

    Github Tools rclone 云存储命令行工具,支持Google Drive, Amazon Drive...

  • wget与curl命令简析

    问题需求 :要下载一个网页中*.txt文件解决方案: 关于linux下命令行下载文件的工具wget与curl的比较...

网友评论

      本文标题:通过wget或curl命令行从 Google Drive下载数据

      本文链接:https://www.haomeiwen.com/subject/fikbydtx.html