天天看點

curl指令具體解釋

  對于windows使用者假設用Cygwin模拟unix環境的話,裡面沒有帶curl指令,要自己裝,是以建議用Gow來模拟,它已經自帶了curl工具,安裝後直接在cmd環境中用curl指令就可,由于路徑已經自己主動給你配置好了。

    linux curl是一個利用URL規則在指令行下工作的檔案傳輸工具。它支援檔案的上傳和下載下傳,是以是綜合傳輸工具,但按傳統,習慣稱url為下載下傳工具。

  一,curl指令參數,有好多我沒實用過,也不知道翻譯的對不正确,假設有誤的地方,還請指正。

  -a/--append 上傳檔案時,附加到目标檔案

  -A/--user-agent <string>  設定使用者代理發送給server

  - anyauth   能夠使用“不論什麼”身份驗證方法

  -b/--cookie <name=string/file> cookie字元串或檔案讀取位置

  - basic 使用HTTP基本驗證

  -B/--use-ascii 使用ASCII /文本傳輸

  -c/--cookie-jar <file> 操作結束後把cookie寫入到這個檔案裡

  -C/--continue-at <offset>  斷點續轉

  -d/--data <data>   HTTP POST方式傳送資料

  --data-ascii <data>  以ascii的方式post資料

  --data-binary <data> 以二進制的方式post資料

  --negotiate     使用HTTP身份驗證

  --digest        使用數字身份驗證

  --disable-eprt  禁止使用EPRT或LPRT

  --disable-epsv  禁止使用EPSV

  -D/--dump-header <file> 把header資訊寫入到該檔案裡

  --egd-file <file> 為随機資料(SSL)設定EGD socket路徑

  --tcp-nodelay   使用TCP_NODELAY選項

  -e/--referer 來源網址

  -E/--cert <cert[:passwd]> client證書檔案和password (SSL)

  --cert-type <type> 證書檔案類型 (DER/PEM/ENG) (SSL)

  --key <key>     私鑰檔案名稱 (SSL)

  --key-type <type> 私鑰檔案類型 (DER/PEM/ENG) (SSL)

  --pass  <pass>  私鑰password (SSL)

  --engine <eng>  加密引擎使用 (SSL). "--engine list" for list

  --cacert <file> CA憑證 (SSL)

  --capath <directory> CA檔案夾 (made using c_rehash) to verify peer against (SSL)

  --ciphers <list>  SSLpassword

  --compressed    要求傳回是壓縮的形勢 (using deflate or gzip)

  --connect-timeout <seconds> 設定最大請求時間

  --create-dirs   建立本地檔案夾的檔案夾層次結構

  --crlf          上傳是把LF轉變成CRLF

  -f/--fail          連接配接失敗時不顯示http錯誤

  --ftp-create-dirs 假設遠端檔案夾不存在,建立遠端檔案夾

  --ftp-method [multicwd/nocwd/singlecwd] 控制CWD的使用

  --ftp-pasv      使用 PASV/EPSV 取代port

  --ftp-skip-pasv-ip 使用PASV的時候,忽略該IP位址

  --ftp-ssl       嘗試用 SSL/TLS 來進行ftp傳輸資料

  --ftp-ssl-reqd  要求用 SSL/TLS 來進行ftp傳輸資料

  -F/--form <name=content> 模拟http表單送出資料

  -form-string <name=string> 模拟http表單送出資料

  -g/--globoff 禁用網址序列和範圍使用{}和[]

  -G/--get 以get的方式來發送資料

  -h/--help 幫助

  -H/--header <line>自己定義頭資訊傳遞給server

  --ignore-content-length  忽略的HTTP頭資訊的長度

  -i/--include 輸出時包含protocol頭資訊

  -I/--head  僅僅顯示文檔資訊

  從檔案裡讀取-j/--junk-session-cookies忽略會話Cookie

  - 界面<interface>指定網絡接口/位址使用

  - krb4 <級别>啟用與指定的安全級别krb4

  -j/--junk-session-cookies 讀取檔案進忽略session cookie

  --interface <interface> 使用指定網絡接口/位址

  --krb4 <level>  使用指定安全級别的krb4

  -k/--insecure 同意不使用證書到SSL網站

  -K/--config  指定的配置檔案讀取

  -l/--list-only 列出ftp檔案夾下的檔案名

  --limit-rate <rate> 設定傳輸速度

  --local-port<NUM> 強制使用本地端口号

  -m/--max-time <seconds> 設定最大傳輸時間

  --max-redirs <num> 設定最大讀取的檔案夾數

  --max-filesize <bytes> 設定最大下載下傳的檔案總量

  -M/--manual  顯示全手動

  -n/--netrc 從netrc檔案裡讀取username和password

  --netrc-optional 使用 .netrc 或者 URL來覆寫-n

  --ntlm          使用 HTTP NTLM 身份驗證

  -N/--no-buffer 禁用緩沖輸出

  -o/--output 把輸出寫到該檔案裡

  -O/--remote-name 把輸出寫到該檔案裡,保留遠端檔案的檔案名稱

  -p/--proxytunnel   使用HTTP代理

  --proxy-anyauth 選擇任一代理身份驗證方法

  --proxy-basic   在代理上使用基本身份驗證

  --proxy-digest  在代理上使用數字身份驗證

  --proxy-ntlm    在代理上使用ntlm身份驗證

  -P/--ftp-port <address> 使用端口位址,而不是使用PASV

  -Q/--quote <cmd>檔案傳輸前,發送指令到server

  -r/--range <range>檢索來自HTTP/1.1或FTPserver位元組範圍

  --range-file 讀取(SSL)的随機檔案

  -R/--remote-time   在本地生成檔案時,保留遠端檔案時間

  --retry <num>   傳輸出現故障時,重試的次數

  --retry-delay <seconds>  傳輸出現故障時,設定重試間隔時間

  --retry-max-time <seconds> 傳輸出現故障時,設定最大重試時間

  -s/--silent靜音模式。不輸出不論什麼東西

  -S/--show-error   顯示錯誤

  --socks4 <host[:port]> 用socks4代理給定主機和端口

  --socks5 <host[:port]> 用socks5代理給定主機和端口

  --stderr <file>

-t/--telnet-option <OPT=val> Telnet選項設定

  --trace <file>  對指定檔案進行debug

  --trace-ascii <file> Like --跟蹤但沒有hex輸出

  --trace-time    跟蹤/具體輸出時,加入�時間戳

  -T/--upload-file <file> 上傳檔案

  --url <URL>     Spet URL to work with

  -u/--user <user[:password]>設定server的使用者和密碼

  -U/--proxy-user <user[:password]>設定代理username與password

  -v/--verbose

  -V/--version 顯示版本号資訊

  -w/--write-out [format]什麼輸出完畢後

  -x/--proxy <host[:port]>在給定的端口上使用HTTP代理

  -X/--request <command>指定什麼指令

  -y/--speed-time 放棄限速所要的時間。默覺得30

  -Y/--speed-limit 停止傳輸速度的限制,速度時間'秒

  -z/--time-cond  傳送時間設定

  -0/--http1.0  使用HTTP 1.0

  -1/--tlsv1  使用TLSv1(SSL)

  -2/--sslv2 使用SSLv2的(SSL)

  -3/--sslv3         使用的SSLv3(SSL)

  --3p-quote      like -Q for the source URL for 3rd party transfer

  --3p-url        使用url,進行第三方傳送

  --3p-user       使用username和password,進行第三方傳送

  -4/--ipv4   使用IP4

  -6/--ipv6   使用IP6

  -#/--progress-bar 用進度條顯示目前的傳送狀态

-M/--manual  顯示全手動

  -t/--telnet-option <OPT=val> Telnet選項設定

  二,經常使用curl執行個體

  1,抓取頁面内容到一個檔案裡

  [root@krlcgcms01 mytest]# curl -o home.html  http://blog.51yip.com

  2,用-O(大寫的),後面的url要詳細到某個檔案,不然抓不下來。我們還能夠用正則來抓取東西

  [root@krlcgcms01 mytest]# curl -O

  3,模拟表單資訊,模拟登入,儲存cookie資訊

  [root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php

  4,模拟表單資訊,模拟登入,儲存頭資訊

  [root@krlcgcms01 mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://blog.51yip.com/wp-login.php

  -c(小寫)産生的cookie和-D裡面的cookie是不一樣的。

  5,使用cookie檔案

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt  http://blog.51yip.com/wp-admin

  6,斷點續傳,-C(大寫的)

  [root@krlcgcms01 mytest]# curl -C -O

  7,傳送資料,最好用登入頁面測試,由于你傳值過去後,curl回抓資料,你能夠看到你傳值有沒有成功

  [root@krlcgcms01 mytest]# curl -d log=aaaa  http://blog.51yip.com/wp-login.php

  8,顯示抓取錯誤,以下這個樣例,非常清楚的表明了。

  [root@krlcgcms01 mytest]# curl -f http://blog.51yip.com/asdf

  curl: (22) The requested URL returned error: 404

  [root@krlcgcms01 mytest]# curl http://blog.51yip.com/asdf

  <HTML><HEAD><TITLE>404,not found</TITLE>

  。。。。。。。。。。。。

  9,僞造來源位址,有的站點會推斷,請求來源位址。

  [root@krlcgcms01 mytest]# curl -e http://localhost http://blog.51yip.com/wp-login.php

  10,當我們經經常使用curl去搞人家東西的時候,人家會把你的IP給屏蔽掉的,這個時候,我們能夠用代理

  [root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html http://blog.51yip.com

11,比較大的東西,我們能夠分段下載下傳

  [root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1 http://blog.51yip.com/wp-

  content/uploads/2010/09/compare_varnish.jpg

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

  Dload  Upload   Total   Spent    Left  Speed

  100   101  100   101    0     0    105      0 --:--:-- --:--:-- --:--:--     0

  [root@krlcgcms01 mytest]# curl -r 100-200 -o img.part2 http://blog.51yip.com/wp-

  100   101  100   101    0     0     57      0  0:00:01  0:00:01 --:--:--     0

  [root@krlcgcms01 mytest]# curl -r 200- -o img.part3 http://blog.51yip.com/wp-

  100  104k  100  104k    0     0  52793      0  0:00:02  0:00:02 --:--:-- 88961

  [root@krlcgcms01 mytest]# ls |grep part | xargs du -sh

  4.0K    one.part1

  112K    three.part3

  4.0K    two.part2

  用的時候,把他們cat一下就OK了,cat img.part* >img.jpg

  12,不會顯示下載下傳進度資訊

  [root@krlcgcms01 mytest]# curl -s -o aaa.jpg

  13,顯示下載下傳進度條

  [root@krlcgcms01 mytest]# curl -# -O

  ######################################################################## 100.0%

  14,通過ftp下載下傳檔案

  [zhangy@BlackGhost ~]$ curl -u username:password -O http://blog.51yip.com/demo/curtain/bbstudy_files/style.css

  101  1934  101  1934    0     0   3184      0 --:--:-- --:--:-- --:--:--  7136

  或者用以下的方式

  [zhangy@BlackGhost ~]$ curl -O ftp://username:password@ip:port/demo/curtain/bbstudy_files/style.css

  15,通過ftp上傳

  [zhangy@BlackGhost ~]$ curl -T test.sql ftp://username:password@ip:port/demo/curtain/bbstudy_files/