LoginSignup
16
8

More than 5 years have passed since last update.

GoogleDriveからcurlでダウンロードする

Posted at

ファイルIDを調べる

共有可能なリンクを探す、で発行されるリンクの?id=以降の部分

https://drive.google.com/open?id=XXX

ファイルサイズが25MB以下の場合

GoogleDriveは25MB以下の場合は以下の通りでDLできる。

curl -L -o hoge.tar.gz "https://drive.google.com/uc?export=download&id=XXXXXXXX"

ファイルサイズが25MBより大きい場合

先ほどのURLでリクエストすると
「Google ドライブではこのファイルのウィルス スキャンを実行することはできません。」
の画面がでるので、その中の(毎回変わる)リンク先を調べる必要がある。

curl -c /tmp/cookie.txt -s -L "https://drive.google.com/uc?export=download&id=XXXXXXXX" |grep confirm |  sed -e "s/^.*confirm=\(.*\)&id=.*$/\1/" | xargs -I{} \
curl -b /tmp/cookie.txt  -L -o hoge.tar.gz "https://drive.google.com/uc?confirm={}&export=download&id=XXXXXXXX"
16
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
8