Curl Download File
- -O: Save the file as the file name specified on the command line
- -O: Save the file to local using the default file name in the URL
- --limit-rate: Speed limit
- -C: Use a breakpoint for large files to continue the transfer function
- --silent: Do not show progress information
# 当文件在下载完成之前结束该进程[[email protected] ~]# curl -O http://www.gnu.org/software/gettext/manual/gettext.html###### ######## 20.1%# 通过添加-C选项继续对该文件进行下载,已经下载过的文件不会被重新下载[[email protected] ~]# curl -C - -O http://www.gnu.org/software/gettext/manual/gettext.html###### ######### 21.1%
Certification Authority
A user name and password can be authorized with the- u option when accessing a page that requires authorization
[[email protected] ~]# curl -u username:password URL通常的做法是在命令行只输入用户名,之后会提示输入密码,这样可以保证在查看历史记录时不会将密码泄露[[email protected] ~]# curl -u username URL
Passing Request Data
The default curl uses the Get method to request data, which can be specified using the --data/-d method to pass data by post
# GET[[email protected] ~]#curl -u username https://XXXXXXXXXX# POST[[email protected] ~]# curl -u username --data "param1=value1¶m2=value" https://XXXXXXXXXX# 也可以指定一个文件,将该文件中的内容当作数据传递给服务器端[[email protected] ~]# curl --data @filename https://XXXXXXXXXX注:默认情况下,通过POST方式传递过去的数据中若有特殊字符,首先需要将特殊字符转义在传递给服务器端,如value值中包含有空格,则需要先将空格转换成%20,如:[[email protected] ~]# curl -d "value%201" http://hostname.com在新版本的CURL中,提供了新的选项 --data-urlencode,通过该选项提供的参数会自动转义特殊字符。[[email protected] ~]# curl --data-urlencode "value 1" https://XXXXXXXXXX除了使用GET和POST协议外,还可以通过 -X 选项指定其它协议,如:[[email protected] ~]# curl -I -X DELETE https://XXXXXXXXXX上传文件[[email protected] ~]#
Curl View Response Time
[[email protected] ~]# curl -o /dev/null -s -w "time_namelookup: "%{time_namelookup}"\ntime_connect: "%{time_connect}"\ntime_appconnect: "%{time_appconnect}"\ntime_pretransfer: "%{time_pretransfer}"\ntime_starttransfer: "%{time_starttransfer}"\ntime_total: "%{time_total}"\n" "https://www.google.com" time_namelookup: 0.005time_connect: 0.016time_appconnect: 0.162time_pretransfer: 0.162time_starttransfer: 0.217time_total: 0.261
Several of these parameters
- -O: Write the HTML and JS returned by Curl to the garbage collection station [/dev/null]
- -S: Drop all status information
- -W,--write-out FORMAT What to output after completion
Time variable
- Time_Total: Total time.
- Time_namelookup:dns parsing time, from the start of the request to the time that DNS parsing is complete.
- Time_connect: Connection time, from start to establish TCP connection to complete the time spent, including the front DNS resolution time, if you need to simply get the connection time, with this time_connect time minus the front time_namelookup time.
- Time_appconnect: Connection Establishment completion time, such as ssl/ssh to establish a connection or to complete three handshake time.
- Time_pretransfer: The time from the start to the ready transfer.
- Time_redirect: Redirect time, including several redirected DNS resolutions, connections, pre-transmissions, transfer times before the last transmission.
- Time_starttransfer: Start transfer time. The time taken by the WEB server to return the first byte of data after the client makes a request.
After the client makes a request, the time it takes for the server to process the request and start sending the data back is: Time_starttransfer–time_connec = 0.201 seconds
The time it takes the client to download data from the server is Time_total–time_starttransfer = 0.044 seconds.
Other variables:
- Url_effective:the URL that is fetched last. This is the most meaningful if you've told Curl to follow Location:headers.
- Filename_effective:the Ultimate FileName This curl writes out to. This was only meaningful if Curl was told to write to a file with the--remote-name or--output option. It ' s most useful in combination with the--remote-header-name option.
- Http_code:http status code, such as 200 success, 301 turn, 404 Not Found, 500 server error, etc.
- Http_connect:the numerical code that is found in the last response (from a proxy) to a Curl connect request. (Added in 7.12.4)
- Size_download: Download size
- Size_upload: Upload Size
- Size_header: The size of the downloaded header
- Size_request: Size of request
- Speed_download: Download speed, Unit-byte/s
- Speed_upload: Upload speed, Unit-byte/s
- Content_type:content-type
- Num_connects:number of new connects made in the recent transfer.
- Num_redirects:number of redirects that were followed in the request.
- Redirect_url:when a HTTP request is made without-l to follow redirects, this variable would show the actual URL a redire CT would take your to.
- Ftp_entry_path:the initial path Libcurl ended up and logging on to the remote FTP server.
- SSL_VERIFY_RESUL:SSL authentication results, return 0 indicates successful authentication.
Curl Command Basic Use small summary