curl


  • 概要
コマンドラインURL転送ライブラリ。
1997年、Daniel Stenberg氏が開発を行った。
多くのダウンロードマネージャーが存在するがcurlの特徴は
  • ライブラリである
  • 対応プロトコルが豊富
  • 連番ファイルに対応(例:img_[1-100],img _{one,two,three})
などの点がある。
Windows 10には、2018年のWindows 10 Ver.1803(RS3)からcurl.exeコマンドが標準で付属されている。




  • History
ProductName Ver ReleaseDate Win Mac Linux Price License SupportDate Home
cURL(カール) 7.75 2021/02/03 Free MIT/FSF not set
7.50.3 2016/09/14

  • Check Version
windows10 curl.exe --version
windowsServer --
Linux --


  • Usage
サブアドレスからDL curl 'http://{1,2,3}.example.com'
a~z連番でDL curl 'ftp://example.com/[a-z].jpg'
5飛びでDL curl 'ftp://example.com/[1-100:5].jpg'
プロキシサーバー指定 curl -x/--proxy host:1080
socks5 proxyサーバー指定 curl --socks5 host:1080
ユーザー認証 curl -u user:password http://example.com/
メソッド指定 curl -X PURGE http://example.com/path/to/url
ファイルに保存 curl -o SaveFile.txt http://example.com/index.html
範囲指定(#n変数) curl http://example.com/ -o "file_#1.txt"
. ## file_one.txt, file_two.txt
. curl http://{one,two}.example.com/[1-2] -o "#1_#2.txt"
. ## one_1.txt one_2.txt, two_1.txt two_2.txt
URLのfilenameで保存 curl -O http://example.com/index.html
連番保存 curl -o 'http://example.com/[1-100].jpg'
帯域制限 curl --limit-rate speed
ステータス表示 curl http://example.com/ -o /dev/null -w "status: %{http_code}, time: %{time_total}\n" 2> /dev/null >> status.log
トレース curl example.com --trace trace.log
HTTPヘッダーを含める curl -i http://example.com/
HTTPヘッダーを保存 curl http://example.com/ -D headerfile.txt
リダイレクト先に再接続 curl -L http://example.com/
redirct先にも認証情報を送る curl --location-trusted http://example.com/
リダイレクト回数指定 curl --max-redirs 50
HTTPリクエストヘッダ指定 curl -H 'host: example.com' example.com
ユーザエージェント指定 curl -A 'Mozilla/4.0' example.com
リファラ指定 curl -e 'http://example.com/demo.cgi' http://example.com/img/demo.jgg
cookie指定 curl -b example.cookie http://example.com/
cookie保存 curl -c example.cookie http://example.com/
POST送信 curl -d username=uname -d password=pw http://example.com/
POST送信(複数) curl -d username=uname -d password=pw http://example.com/ & -d form1=arg1 http://example.com/
POST送信(ファイル) curl -F password=@/etc/passwd -name formID example.com
POST送信(ファイル, enc指定) curl -F "web=@index.html;type=text/html" example.com
POST送信(URLenc自動) curl -d username=uname -data-url-encode -d password=pw http://example.com/
圧縮 curl --compressed
SSL証明書警告を無視 curl -k http://example.com/
. ※あえて-k付けずに実施で簡易httpsチェック
FTP curl ftp://example.com/path/to/file
FTP リスト表示 curl ftp://example.com/path/to/directory
FTP ファイル名のみ表示 curl -l ftp://example.com/path/to/directory
FTP ディレクトリ作成 curl ftp://example.com/mk/dir/ --ftp-create-dirs
FTP アップロード curl -T /path/to/file ftp://example/com/path/to/upload
FTP EPSVパッシブ無効 curl ftp://examle.com/ --disable-epsv
エラーの一部表示 curl -sS http://example.com/file.txt
. ※全く表示させたくないならスモールsのみ。ラージSを加えると重要度の高いエラーは表示される

  • 参考
curlのオプション勉強したのでまとめ
<http://hogem.hatenablog.com/entry/20091122/1258863440>

  • OS別 利用方法
Windows
公式サイトからWindows用ファイルをダウンロード
curl.exeに対してWindows環境変数の設定が必要

MacOS
標準搭載
ターミナルからそのまま利用できる

Linux
標準搭載

Android

iOS

  • 参考
WindowsにcURLコマンドを入れて動作確認する - いろいろやってみるにっき
<http://shigeo-t.hatenablog.com/entry/2016/02/24/050340>
最終更新:2022年04月26日 19:10