23. CURL 常用指令
下載下傳單個檔案,預設将輸出列印到标準輸出(STDOUT)中
# curlhttp://localhost:8888/index.html
通過 -O/-o 選項儲存下載下傳的檔案到指定的檔案夾
-o:将檔案儲存為指令行中指定的檔案名(就是重命名)
# curl -o index2.htmlhttp://localhost:8888/index.html
-O:使用 URL 中預設的檔案名稱儲存檔案到本地
# curl -O http://localhost:8888/index.html
同時擷取多個檔案
curl -O URL1 -O URL2
預設情況下CURL不會發送HTTP Location headers(重定向).當一個被請求頁面移動到另一個站點時,
會發送一個HTTP Loaction header作為請求,然後将請求重定向到新的位址上
# curl -L http://localhost:8888/index.html
斷點續傳
-C:斷點續傳功能,已經下載下傳過的檔案不會被下載下傳
# curl -C -O http://localhost:8888/index.html
對 CURL 使用網絡限速
# curl --limit-rate 1000B -O http://localhost:8888/index.html
當下載下傳一個檔案時,可對該檔案的最後修改日期進行判斷,如果該檔案在指定日期(2011-12-21)内修改過,就進行下載下傳,否則不下載下傳
# curl -z 21-Dec-11 http://localhost:8888/index.html
-u:在通路需要授權的頁面時,可以指定使用者名和密碼,一般都隻提供使用者不提供密碼,否則會在曆史記錄裡被找到
# curl -u username:password http://localhost:8888/pub/index.html
從 FTP 伺服器下載下傳檔案
# 列出 pub 路徑下的所有檔案和檔案夾
# curl -u name:pass -O http://localhost:8888/pub/
# 下載下傳 pub 路徑下的 index.html 檔案
# curl -u name:pass -O http://localhost:8888/pub/index.html
上傳檔案到 FTP 伺服器
-T:上傳本地檔案到 FTP 伺服器
# 上傳單個檔案到 FTP 伺服器
# curl -u user:pass -T 1.txt http://localhost:8888/pub/index.html
# 上傳多個檔案到 FTP 伺服器
# curl -u user:pass -T "{file1, file2, file3}" http://localhost:8888/pub/index.html
為 CURL 設定代理
# curl -x proxysever.test.com:3128 http://localhost:8888/pub/index.html
儲存與使用網站 cookie 資訊
# 将網站的 cookie 儲存到 1.txt 檔案中
# curl -D 1.txt http://localhost:8888/pub/index.html
# 将網站的cookies資訊儲存到sugarcookies檔案中
curl -D sugarcookies http://localhost/sugarcrm/index.php