# #curl命令
The Curl command is a powerful network tool that can download files via HTTP, FTP, and so on, and can also upload files.
# # # #1. Download a single file and print the output to standard output (STDOUT) by default
```
Curl http://www.baidu.com
```
# # # #2. Save the downloaded file to the specified file with the-o/-o option:
-O: Save the file as a file in the specified file name (mypage.html) on the command line
```
Curl-o mypagebaidu.html http://www.baidu.com
```
You can also use the turn character ">" to turn output to output
```
Curl http://www.yahoo.com >mypageyahoo.html
```
-O: Save the file to local using the default file name in the URL
```
Curl-o http://www.qq.com
```
Get multiple files at the same time
```
Curl-o Www.sohu.com-O www.sina.com.cn
```
# # # #3. Breakpoint Continuation:
When the file ends the process before the download is complete, you can continue to download the file with the-C option (files that have already been downloaded will not be downloaded)
```
Curl-o http://www.gnu.org/software/gettext/manual/gettext.html
Curl-c-O http://www.gnu.org/software/gettext/manual/gettext.html
```
# # # # #4. Use network speed limit for curl
Limit the maximum network usage of curl with the--limit-rate option
```
Curl--limit-rate 1000b-o
Http://www.gnu.org/software/gettext/manual/gettext.html
```
# # # #5. Download files that have been modified in the specified time
When downloading a file, you can determine the last modified date of the file, if the file has been modified within the specified date, download it, otherwise it will not be downloaded.
This feature can be achieved by using the-Z option:
```
If the yy.html file has been updated since 2011/12/21, it will not be downloaded.
Curl-z 21-dec-11 http://www.example.com/yy.html
```
# # # # #6. Curl Authorization
A user name and password can be authorized with the-u option when accessing a page that requires authorization
```
Curl-u Username:password URL
```
It is common practice to enter only the user name at the command line and then prompt for a password, which guarantees that the password will not be compromised when viewing history
```
Curl-u username URL
```
# # # # #7. FTP download
Curl also supports FTP downloads, and if you specify a file path in the URL instead of a specific file name to download, curl lists all the file names in that directory rather than downloading all the files in that directory
```
List all folders and files under public_html
Curl-u Ftpuser:ftppass-o ftp://ftp_server/public_html/
Download xss.php file
Curl-u Ftpuser:ftppass-o ftp://ftp_server/public_html/xss.php
```
# # # # #8. Uploading files to an FTP server
The-t option uploads the specified local file to the FTP server
```
Uploading the MyFile.txt file to the server
Curl-u ftpuser:ftppass-t myfile.txt ftp://ftp.testserver.com
Upload Multiple files simultaneously
Curl-u ftpuser:ftppass-t "{file1,file2}" ftp://ftp.testserver.com
Save content from standard input to a file specified by the server
Curl-u Ftpuser:ftppass-t-Ftp://ftp.testserver.com/myfile_1.txt
```
# # # #9. Saving and using Web site cookie information
```
Save cookies from the website to the Sugarcookies file
curl-d sugarcookies http://localhost/sugarcrm/index.php
Use the last saved cookie information
Curl-b sugarcookies http://localhost/sugarcrm/index.php
```
# # # # #10. Passing Request data
Default curl uses Get method to request data, in this way directly through the URL to pass the data
```
Curl-u username Https://api.github.com/user?access_token=XXXXXXXXXX
```
You can use the--data/-d method to specify that data is passed by post
```
Curl-u username--data "Param1=value1¶m2=value" https://api.github.com
```
You can also specify a file to pass the contents of the file as data to the server side
```
Curl--data @filename Https://github.api.com/authorizations
```
By default, if there are special characters in the data passed through post, you first need to pass the special character escapes to the server side, if the value contains spaces, you need to convert the space to%20
```
Curl-d "value%201" http://hostname.com
```
In the new version of Curl, a new option--data-urlencode is provided, and the parameters provided by this option automatically escape special characters.
```
Curl--data-urlencode "value 1" http://hostname.com
```
In addition to using the Get and post protocols, additional protocols can be specified with the-X option
```
Curl-i-X DELETE HTTPS://API.GITHUB.CIM
```
POST a Jason
Here you want to post JSON data to the interface, you need to set a good header, that is: ' Content-type ': ' application/x-www-form-urlencoded ', ' CharSet ': ' Utf-8 ', ' Accept ': ' Text/plain '.
```
Curl-i-X post-h "' Content-type ': ' application/x-www-form-urlencoded ', ' CharSet ': ' Utf-8 ', ' Accept ': ' Text/plain '"-d ' Json_data={"a": "AAA", "B": "BBB", "data": [{"C": "CCC", "D": "DDD", "keywords": [{"E": "Eee", "F": "FFF", "G": "GGG"}]}]} ' Url
```
Curl Command Parameters
-a/--append attaching to the destination file when uploading a file
-a/--user-agent <string> set up user agent to send to server
-Anyauth can use "any" authentication method
-b/--cookie <name=string/file> Cookie string or file read location
-Basic authentication using HTTP
-b/--use-ascii using ASCII/text transfer
-c/--cookie-jar <file> Write cookies to this file after the operation is complete
-c/--continue-at <offset> Breakpoint Continuation
-d/--data <data> HTTP Post mode transfer data
--data-ascii <data> Post data in ASCII mode
--data-binary <data> post data in binary mode
--negotiate using HTTP Authentication
--digest using digital authentication
--DISABLE-EPRT prohibit the use of eprt or LPRT
--DISABLE-EPSV prohibit the use of EPSV
-d/--dump-header <file> Write header information to this file
--egd-file <file> Set EGD socket path for random data (SSL)
--tcp-nodelay using the Tcp_nodelay option
-e/--referer Source URL
-e/--cert <cert[:p asswd]> client certificate file and password (SSL)
--cert-type <type> certificate file type (Der/pem/eng) (SSL)
--key <key> private Key file name (SSL)
--key-type <type> private key file type (Der/pem/eng) (SSL)
--pass <pass> private Key password (SSL)
--engine <eng> Encryption engine use (SSL). "--engine List" for list
--cacert <file> CA Certificate (SSL)
--capath <directory> CA directory (made using C_rehash) to verify peer against (SSL)
--ciphers <list> SSL Password
--compressed requirements Return is a compressed situation (using deflate or gzip)
--connect-timeout <seconds> Set Maximum request time
--create-dirs Creating a directory hierarchy of local directories
--crlf upload is to convert LF into CRLF
HTTP error not displayed when-f/--fail connection fails
--ftp-create-dirs If the remote directory does not exist, create a remote directory
--ftp-method [MULTICWD/NOCWD/SINGLECWD] controlling the use of CWD
--FTP-PASV using PASV/EPSV instead of ports
--ftp-skip-pasv-ip when using PASV, ignore the IP address
--ftp-ssl attempt to use SSL/TLS for FTP data transfer
--FTP-SSL-REQD requires SSL/TLS for FTP data transfer
-f/--form <name=content> analog HTTP form submission data
-form-string <name=string> analog HTTP form submission data
-g/--globoff Disable URL sequence and range using {} and []
-g/--get sending data in a get way
-h/--help Help
-h/--header <line> Custom header information to the server
--ignore-content-length the length of the HTTP header information ignored
-i/--include output includes protocol header information
-i/--head Display only Document information
-j/--junk-session-cookies Ignore session Cookies
-Interface <interface> Specify network interface/address usage
-KRB4 < level > enable with the specified security level KRB4
-j/--junk-session-cookies read file into ignore session cookie
--interface <interface> using specified network interface/address
--KRB4 <level> using KRB4 with the specified security level
-k/--insecure allow non-use of certificates to SSL sites
-k/--config The specified configuration file read
-l/--list-only lists the file names under the FTP directory
--limit-rate <rate> Set Transfer speed
--local-port<num> forcing the use of local port numbers
-m/--max-time <seconds> Set Maximum transfer time
--max-redirs <num> Set the maximum number of read directories
--max-filesize <bytes> Set the maximum amount of files to download
-m/--manual Display Full Manual
-N/--NETRC to read the user name and password from the Netrc file
--netrc-optional use. netrc or URL to overwrite-n
--NTLM using HTTP NTLM authentication
-n/--no-buffer Disabling buffered output
-o/--output writes the output to the file
-o/--remote-name writes the output to the file, preserving the file name of the remote
-p/--proxytunnel using an HTTP proxy
--proxy-anyauth Select either Proxy authentication method
--proxy-basic using Basic authentication on the agent
--proxy-digest using digital authentication on the proxy
--PROXY-NTLM using NTLM authentication on the agent
-p/--ftp-port <address> use port address instead of PASV
-q/--quote <cmd> Send a command to the server before transferring the file
-r/--range <range> retrieving byte ranges from http/1.1 or FTP servers
--range-file Read (SSL) random files
-r/--remote-time Preserve remote file time when generating files locally
--retry <num> Number of retries when there is a problem with the transmission
--retry-delay <seconds> Set retry interval when problems occur with transmission
--retry-max-time <seconds> Set Maximum retry time when there is a problem with the transmission
-s/--silent Mute mode. Don't output anything.
-s/--show-error Display Error
--SOCKS4
--SOCKS5
--trace <file> debug a specified file
--trace-ascii <file> like--trace but no hex output
Add time stamp when--trace-time trace/verbose output
-t/--upload-file <file> Uploading files
-u/--user <user[:p assword]> setting up the user and password for the server
-u/--proxy-user <user[:p assword]> Setting the proxy user name and password
-v/--version displaying version information
-w/--write-out [format] what output is complete
-x/--proxy
-x/--request <command> Specify what commands
-y/--speed-time the time required to abandon the speed limit. Default is 30
-y/--speed-limit Stop transmission speed limit, speed time ' s
-z/--time-cond Transfer Time setting
-0/--http1.0 Using HTTP 1.0
-1/--tlsv1 using TLSV1 (SSL)
-2/--sslv2 using SSLv2 (SSL)
-3/--sslv3 used by SSLv3 (SSL)
--3p-url using URLs for third-party transfers
--3p-user third-party transfer using username and password
-4/--ipv4 using IP4
-6/--ipv6 using IP6
-#/--progress-bar Displays the current delivery status with a progress bar
Curl Command Collation