curlã¯wget, lwp-request(GET, HEAD), lynxã¨åããããªcliã®http clientãã ã¨æã£ã¦ãããã£ã¨æ©è½ããããããªã®ã§ãman curlèªãã§è²ã 調ã¹ã¦ã¿ããHTTP(S)以å¤ã«ãããªã対å¿ãã¦ãã
curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE).
ã¨ããããè¯ã使ããããªhttp, ftpé¢é£ã®ã¡ã¢ãDLã ããããªãã¦ãã¢ãããã¼ããã§ããã®ãç´ æ´ãããã
åºæ¬
syntax
curl [optinons] URL
URL
It will then default to HTTP but try other protocols based on often-used host name prefixes.
For example, for host names starting with "ftp." curl will assume you want to speak FTP.
protocolãçç¥ããã¨defaultã§ã¯HTTPã«ãªããã©ãftp.exmaple.comã®ãããªhostã ã£ããååããæ¨æ¸¬ãã¦FTPããã
ãã¨{}ã[]ã使ã£ã¦ãè¤æ°æå®ãããã¨ãå¯è½ããã ãã{}ã¯ã·ã§ã«ãå±éãã¦ãã¾ãã®ã§ç¯å²æå®ã®ã¨ãã¯ã·ã³ã°ã«ã¯ã©ã¼ãããã»ããç¡é£ã
- ã³ã³ãã§è¤æ°æå®
curl 'http://{one,two,three}.example.com'
- []ã使ã£ã¦ç¯å²æå®
curl 'ftp://example.com/[1-10].txt' curl 'ftp://example.com/[a-z].txt'
1.txt ~ 10.txt, a.txt ~ z.txtã¾ã§ãDLã
- ç¯å²ã®stepãæå®
ãããåºæ¥ãã®ã¯curl 7.15.1以é
curl 'ftp://example.com/[1-10:2].txt'
2ã¤ãã¤ãã¤ã¾ã1, 3, 5, 7, 9.txtãDLã
ã¦ã¼ã¶èªè¨¼
- -u/--user user[:password]
httpã®basicèªè¨¼ãftpã®ãã°ã¤ã³ã¨ãã«ã
curl -u user:password http://example.com/
å¼æ°ã«passwordãä¸ããªããã°ãpromptã§èãããã(historyã«æ®ããããªãã¨ãã¨ã)
ã¡ã½ãããæå®
varnish, webdav ãªã©ãå©ç¨ããéã«ãä¾ãã°varnishã§cacheãpurgeããéã«-X PURGE ãæå®ã(varnishå´ã®vclã§ããããè¨å®ããã¦ããå¿ è¦ãã)
curl -X PURGE http://example.com/path/to/url
ãã¡ã¤ã«ã«ä¿å
defualtã§ã¯çµæãæ¨æºåºåã«åºãã®ã§ããã¡ã¤ã«ã«ãªãã¤ã¬ã¯ããããã-oã§filenameãæå®ãã¦ä¿åã
curl -o index.html http://example.com/index.html
ç¯å²æå®ã使ã£ã¦ããã¨ãã¯"#n"ã®ç¹æ®å¤æ°ã使ããã
curl http://{one,two}.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ã§ä¿å
- -O/--remote-name
-oã¨ä¼¼ã¦ãããã©ããã£ã¡ã®ã»ãã楽ãããã¢ã¯ã»ã¹ãããã¡ã¤ã«ãhoge.txtãªããããã¨åãååã§ä¿åããã
curl -O http://exapmle.com/index.html ## index.htmlã¨ãã¦ä¿åããã
-oã®ä¾ã®ããã«hostååãå±éãã¦ããå ´åã¯ã ãã ãã©ããã¡ã¤ã«åãå±éãã¦ããã ããªã
curl -O 'http://example.com/image/image[001-100].jpg'
ã¨ããã001.jpgãã100.jpgã¾ã§ä¿åããã-oã¿ãã#1ã¨ãæ¸ããªãã¦ããã
帯åå¶é
- --limit-rate speed
speedã¯10k, 1m, 1gãªã©ã§ãåç·/ãµã¼ãã«è² è·ãæããããªãã¨ãã«ã
å種statusçµæã表示
- -w/--write-out format
ç¹æ®å¤æ°ã§%{variable_name}ã®ãããªformatã使ãããhttp_codeãtime_totalãªã©ã詳細ã¯man curlãä¾ãã°ã
curl http://example.com/ -o /dev/null -w "status: %{http_code}, time: %{time_total}\n" 2> /dev/null >> status.log
ã¨ããå®æçã«æµãã¦ããã°ãhttpã®statusã¨å¿çæéããã°ã«åãããã¿ãããªã
traceãã
Enables a full trace dump of all incoming and outgoing data
tcpdump -Xã®ãããªæãã16é²æ°ã¨ASCIIã表示ãããå°ã£ãã¨ãã«debugããã¨ãã«ä½¿ãããã
- --trace filename
filenameã"-"ã«ããã¨æ¨æºåºåã«åºãã
curl example.com --trace trace.log
- --trace-ascii filename
--traceã¨ä¼¼ã¦ãããã16é²æ°ã¯è¡¨ç¤ºããªãããã¨ASCIIã¯LFã§æ¹è¡ãã¦è¡¨ç¤ºãã¦ãããã
This is very similar to --trace, but leaves out the hex part and only shows the ASCII part of the dump
httpé¢é£
HTTP headerã表示
- -i/--include
åºåã«HTTP-headerãå«ãããapacheã®è¨å®ç¢ºèªãããã¨ãã«ä¾¿å©ã
HTTP headerã®ã¿è¡¨ç¤º
- -I/--head
HEADã¡ã½ãããéã£ãã¨ãã¨åããbodyã¯è¡¨ç¤ºããªãã
HTTP headerãfileã«ä¿å
- -D/--dump-header file
redirectå ã«åæ¥ç¶ãã
- -L/--location
30Xã§Redirectãè¿ã£ã¦ããã¨ãã«ãLocationãããã®URLã«ããä¸åº¦ã¢ã¯ã»ã¹ãããlwp-requestã®-Sãªãã·ã§ã³ã®ãããªæãã§ãããã¯é常ãä»ãã¨ããã»ããè¯ãããã
curl -L http:/example.com/
èªè¨¼æ å ±ãéãã¨ã
--userã§èªè¨¼æ å ±ãéã£ãå ´åã¯redirectå ã®hostã«ã¯éãããªããredirectå ã®hostã«ãèªè¨¼æ å ±ãéãå ´åã¯
curl --location-trusted http://example.com/
ç¡éã«ä½¿ãã¨ããã£ããæªãããªãµã¤ãã«redirectããã¦ãã¹ã¯ã¼ãçã¾ããããªãã®ã§ãä¿¡é ¼ãã¦ããµã¤ãã§ã®ã¿ä½¿ãã¹ããã¨ã®ãã¨ã
redirectã®æ大åæ°ãæå®
- --max-redirs num
ã«ã¼ãããã¨ãããªãã®ã§ãããã¦æå®ãããdefaultã¯50ã
HTTP request ãããæå®
- -H/--header header_string
Hostããããè²ããªããããéãã¤ãããã¨ãã«ã
curl -H 'host: hoge.example.com' example.com
ã¦ã¼ã¶ã¨ã¼ã¸ã§ã³ãæå®
- -A/--user-agent agetn_string
âã®-Hã§User-Agent: hogeã¨æå®ãã¦ãè¯ãã
curl -A 'Mozilla/4.0' example.com
ãªãã¡ã©æå®
- -e/--referer URL
ããã-Hã§æå®ãã¦ãè¯ããã©ãââãªç»åã¨ããDLããã¨ãã¨ãã«å¤§æ´»èºï¼
curl -e 'http://example.com/upload.cgi' http://example.com/img/hoge.jgg
cookieãéä¿¡
cookie_dataã®formatã¯"NAME1=VALUE1; NAME2=VALUE2"ã®ãããªæååãããcookie_dataã«"="ãå«ã¾ãã¦ããªãå ´åãfilenameã¨ãã¦æ±ããããã¤ã¾ããå¾è¿°ãããªãã·ã§ã³ã§cookieãä¿åãã¦ããã°
curl -b example.cookie http://example.com/
cookieãä¿å
- -c/--cookie-jar file_ame
filenameã"-"ã ã¨ãcookieã¯æ¨æºåºåã«åºãã
curl -c example.cookie http://example.com/
POSTã§formãã¼ã¿éä¿¡
- -d/--data name=value
ãã¼ã¿ãè¤æ°ããå ´åã¯'&'ã§ã¤ãªãããã-dãè¤æ°åæå®ãã¾ãã-dãªãã·ã§ã³ã®å ´åã¯content-typeã¯"application/x-www-form-urlencoded"ã«ãªããfileãéä¿¡ããå ´åã¯æ¬¡ã®-Fã§ã
curl -d username=hoge -d password=fuga http:/example.com/
'%'ã'&'ãªã©ãéä¿¡ããå ´åã¯URLã¨ã³ã³ã¼ãããã'%25', '%26'ãªã©ã®å¤ãéããªãã¨ãã¡ãèªåçã«å¤æããã¦éä¿¡ãããå ´åã¯--data-urlencodeã使ã
POSTãã¼ã¿ãurlã¨ã³ã³ã¼ããã¦éä¿¡
- --data-urlencode
curl -d user=hoge --data-urlencode pass='pass&word' http://example.com/
POSTã§fileãupload
- -F/--form name=content
ãã¡ãã¯content-typeã¯"multipart/form-data"ã«ãªããcontentã®åã«"@"ãããã¨ãfilenameã¨ãã¦æ±ããããnameã¯formã®IDã
curl -F password=@/etc/passwd password.example.com
uploadããfileã®content-typeã®æå®ãå¯è½ã
curl -F "[email protected];type=text/html" url.example.com
ã³ã³ãã³ãå§ç¸®
- --compressed
HTTPéä¿¡ãå§ç¸®ãã¦ãå±éããããã®ãåºåã«è¡¨ç¤ºãããlibcurlãsupportãã¦ããã¢ã«ã´ãªãºã ãé¸æããããHTTPãããè¦ãã¨ããããªã®ã追å ãããã
Accept-Encoding: deflate, gzip
ãã¡ããwebãµã¼ãå´ãã³ã³ãã³ãå§ç¸®ã«å¯¾å¿ãã¦ããå¿
è¦ããã
SSL証ææ¸ã®è¦åãç¡è¦ãã
- -k / --insecure
defaultã§ã¯è¨¼ææ¸ã®è¦åãããã¨ãæ¥ç¶ã§ããªãã(CNãéããæéãåãã¦ãããä¸é証ææ¸ããããããªã©)
$ curl https://badcommonname.example.com/ url: (60) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed More details here: http://curl.haxx.se/docs/sslcerts.html (ä¸ç¥) If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option. $ curl --insecure curl https://badcommonname.example.com/ #### => ã³ã³ãã³ãã表示ããã
è¨ãæããã°ãcurlã§httpsã®ç°¡æãã§ãã¯ãã§ããã
ftp
httpã ããããªããftpãã¦ã³ãã¼ã/ã¢ãããã¼ããã§ãããdefaultã¯anonymous loginãããã¨ããã®ã§é©å®-uã§æå®ãã¾ããhttpã¨åãããã¡ã¤ã«ã®å 容ã¯æ¨æºåºåã«åºãã®ã§ãªãã¤ã¬ã¯ããããã-oã-Oãªã©ã§fileã«ä¿åããã»ããè¯ãã
curl ftp://example.com/path/to/file
list表示
ãã£ã¬ã¯ããªãæå®ããã¨ä¸è¦§ã表示ãããã
curl ftp://example.com/path/to/dir
filenameã ã表示
- -l/--list-only
ãã£ã¬ã¯ããªæå®æã«ãtimestampãªã©ã表示ããªãã
ãã£ã¬ã¯ããªä½æ
- --ftp-create-dirs
defaultã§ã¯åå¨ããªããã£ã¬ã¯ããªãpathã«æå®ããã¨å¤±æããã
$ curl ftp://example.com/not/exist/ curl: (9) Server denied you to change to the given directory $ curl ftp://example.com/not/exist/ --ftp-create-dirs
mkdir -p(mkdirhier)ã¿ããã«è¦ªãã£ã¬ã¯ããªããªãã£ãå ´åã¯è¦ªãã£ã¬ã¯ããªãä½æãã¦ãããã
fileãftp upload
- -T/--upload-file file
curl -T /path/to/file ftp://example.com/path/to/upload
å人çã«ã¯ãã£ã¤ä¾¿å©ã§ãæ°ã«å
¥ãæ©è½ã§ããä»ã¾ã§ãµã¼ãéã§ãã¡ã¤ã«è»¢éããã¨ãã«æåã§ftp/scpå©ãã¦ããããªãããã¨ãmanãè¦ã¦ããhttpã§ããããããããã©ãã©ãã£ã¦uploadãããã ãããwebdavï¼
EPSV (extended passive)ãç¡å¹ã«ãã
- --disable-epsv
defaultã§ã¯EPSVã試è¡ãã¦ãããããã¡ãªããã®å¾ã«PASVã¢ã¼ãã«ãªããFTPãµã¼ããEPSVã«å¯¾å¿ãã¦ã¦ããNATã«ã¼ã¿ã¨ããEPSVã解éãã¦ãããªãã¨ãã¿ã¤ã ã¢ã¦ããå¾ ããªãã¨ãããªãããããªã¨ãã«æå®ããã¨è¯ãã
EPSVã«ã¤ãã¦ã¯ãã£ã¡ã§ã