9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GoogleDriveからファイルをwgetでダウンロードするためのコマンド

Last updated at Posted at 2019-09-05

背景

1.GoogleDriveにあるファイルをサーバーに配置したかった。
2.ファイルは大きい(2GBくらい)ので「ローカルにダウンロードしてサーバーへアップロード」という手順はやりたくなかった。
3.サーバーからGoogle Driveのファイルをwgetコマンドなどでダウンロード出来ないかを調べた。

解決策

こちらのコメントがベストでした。
https://gist.github.com/iamtekeste/3cdfd0366ebfd2c0d805#gistcomment-2359248

以下簡単に翻訳

セットアップ:

下記のコードを ~/.bash_aliases に追加

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

新しくセッションを開始する
(もしもコマンドが見つからないと言われたら source ~/.bash_aliases で読み込めるはず)

使い方:

gdrive_download fileのid 保存先のファイル名

file_idとは

スクリーンショット 2019-09-05 13.44.27.png **file_id**はGoogleDriveの画面からファイルを右クリックして、「共有可能なリンクを取得」を選択した際に表示されるURLの `?id=hogehoge` のhogehoge です
9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?