Linux curl command detailed explanation and example sharing (transfer)



linux curl is a file transfer tool that works from the command line using URL rules. It supports file uploading and downloading, so it is a comprehensive transmission tool, but according to tradition, it is customary to call url a download tool.

  First, there are a lot of curl command parameters that I have not used, and I don't know if the translation is correct. If there are any mistakes, please correct me.

  -a/--append append to target file when uploading file

  -A/--user-agent <string> set user agent to send to server

  - anyauth can use "any" authentication method

  -b/--cookie <name= string/file> cookie string or file read location

  - basic use HTTP basic authentication

  -B/--use-ascii use ASCII/text transfer

  -c/--cookie-jar <file> write cookies to In this file

  -C/--continue-at <offset> breakpoint continue

  -d/--data <data> HTTP POST method to transmit data

  --data-ascii <data> Post data in ascii method

  --data- binary <data> Post data in binary

  --negotiate use HTTP authentication

  --digest use digital authentication

  --disable-eprt disable EPRT or LPRT

  --disable-epsv disable 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 use TCP_NODELAY option

  -e/--referer source URL

  -E/--cert <cert[:passwd]> client certificate file and password (SSL)

  --cert-type <type> certificate file type (DER/PEM/ ENG) (SSL)

  --key <key> private key filename (SSL)

  --key-type <type> private key file type (DER/PEM/ENG) (SSL)

  --pass <pass> private key password ( SSL)

  --engine <eng> Encryption engine to 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 cipher

  --compressed requires the return to be compressed (using deflate or gzip)

  --connect-timeout <seconds> set the maximum request time

  --create-dirs create a directory hierarchy for the local directory

  --crlf upload is to convert LF to CRLF

  -f/--fail do not show http errors when connection fails

  --ftp -create-dirs Create the remote directory if it doesn't exist

  --ftp-method [multicwd/nocwd/singlecwd] control the use of CWD --ftp

  -pasv use PASV/EPSV instead of port

  --ftp-skip-pasv-ip use When PASV, ignore the IP address

  --ftp-ssl try to use SSL/TLS for ftp data transmission

  --ftp-ssl-reqd require SSL/TLS for ftp data transmission

  -F/--form <name=content > Simulate http form submission data

  -form-string <name=string> Simulate http form submission data

  -g/--globoff Disable URL sequences and ranges Use {} and []

  -G/--get Send data as get

  -h/--help help

  -H/--header <line>Custom headers passed to the server

  --ignore-content-length Length of HTTP headers to ignore

  -i/--include include protocol header information when outputting

  -I/--head only display document information read

  from file -j/--junk-session-cookies ignore session cookies

  - interface <interface> specifies network interface/address use

  --krb4 <level> enable with specified security level krb4

  -j/--junk-session-cookies read file and ignore session cookies

  --interface <interface> use specified network interface/address

  --krb4 <level> use specified Security level krb4

  -k/--insecure Allow to SSL site without certificate

  -K/--config specified configuration file read

  -l/--list-only list file names in ftp directory

  --limit-rate <rate> set transfer speed

  --local-port<NUM> force use of local port number

  -m/--max-time <seconds> set maximum transfer time

  --max-redirs <num> set maximum number of directories to

  read- -max-filesize <bytes> Set the maximum amount of files downloaded

  -M/--manual show full manual

  -n/--netrc Read username and password from netrc file

  --netrc-optional use .netrc or URL to override -n

  --ntlm use HTTP NTLM authentication

  -N/--no-buffer disable buffered output

  -o/--output write output to this file

  -O/- -remote-name write output to this file, keeping filename of remote file

  -p/--proxytunnel use HTTP proxy

  --proxy-anyauth choose any proxy authentication method

  --proxy-basic use basic auth on proxy verify

  --proxy-digest use digital authentication

  on proxy --proxy-ntlm use ntlm authentication on proxy

  -P/--ftp-port <address> use port address instead of PASV

  -Q/--quote <cmd> Before file transfer, send command to server

  -r/--range <range> retrieve

  random file from HTTP/1.1 or FTP server byte range --range-file read (SSL)

  -R/--remote -time When generating files locally, keep the remote file time

  --retry <num> The number of retries when there is a problem with the transmission

  --retry-delay <seconds> When there is a problem with the transmission, set the retry interval

  --retry-max-time <seconds> Set max retry time when there is a problem with transmission

  -s/--silent silent mode. output nothing

  -S/--show-error show error

  --socks4 <host[:port]> proxy the given host and port

  with socks4 --socks5 <host[:port]> proxy the given host and port with socks5

  --stderr <file>
-t/--telnet-option <OPT=val> Telnet option setting

  --trace <file> debug the specified file --trace   -

  ascii <file> Like --trace but no hex output-

-trace-time add timestamp when tracing/verbose output

  -T/--upload-file <file> upload file

  --url <URL> Spet URL to work with

  -u/--user <user[:password]> set server user and password

  -U/--proxy-user <user[:password]>set proxy username and password

  -v/--verbose

  -V/--version show version info

  -w/--write-out [ format] what output is done after

  -x/--proxy <host[:port]> Use HTTP proxy on given port

  -X/--request <command> specify what command

  -y/--speed-time Time to give up speed limit. The default is 30

  -Y/--speed-limit stop transmission speed limit, speed time' seconds

  -z/--time-cond transmission time setting

  -0/--http1.0 use HTTP 1.0

  -1/--tlsv1 use TLSv1 (SSL)

  -2/--sslv2 use SSLv2 (SSL)

  -3/--sslv3 use SSLv3 (SSL)

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

  --3p-url use url, for third-party transfer

  --3p-user use username and password for third-party transfer

  -4/--ipv4 use IP4

  -6/--ipv6 use IP6

  -#/--progress-bar Show the current progress bar transfer state

  -a/--append when uploading file, append to destination file

  -A/--user-agent <string> set user agent to send to server

  - anyauth can use "any" authentication method

  -b/--cookie <name=string/file> cookie string or file read location

  -basic use HTTP basic authentication

  -B/--use-ascii use ASCII/text transfer

  -c/--cookie-jar <file > After the operation is over, write the cookie to this file

  -C/--continue-at <offset> breakpoint continue

  -d/--data <data> HTTP POST method to transmit data

  --data-ascii <data> to Post data in ascii mode

  --data-binary <data> Post data in binary mode

  --negotiate use HTTP authentication

  --digest use digital authentication

  --disable-eprt disable EPRT or LPRT

  --disable-epsv disable EPSV

  -D/--dump-header <file> write header information to this file

  --egd-file <file> set EGD socket path for random data (SSL)

  --tcp-nodelay use TCP_NODELAY option

  -e/ --referer source URL

  -E/--cert <cert[:passwd]> 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 to 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 ciphers

  --compressed Require the return to be compressed (using deflate or gzip)

  --connect-timeout <seconds > set max request time

  --create-dirs build directory hierarchy of local directory

  --crlf upload is to convert LF to CRLF

  -f/--fail don't show http error when connection fails

  --ftp-create-dirs if remote directory doesn't exists, create a remote directory

  --ftp-method [multicwd/nocwd/singlecwd] Control the use of CWD

  --ftp-pasv Use PASV/EPSV instead of port

  --ftp-skip-pasv-ip When using PASV, ignore the IP address

  --ftp-ssl Attempt to use SSL/TLS for ftp data transmission

  --ftp-ssl- reqd requires SSL/TLS for ftp data transfer

  -F/--form <name=content> emulate http form submission data

  -form-string <name=string> emulate http form submission data

  -g/--globoff disable url sequences and scope use {} and []

  -G/--get to send data as get

  -h/--help help

  -H/--header <line>Custom header information passed to the server

  --ignore-content- length length of ignored HTTP headers

  -i/--include include protocol headers when outputting

  -I/--head only show document information read

  from file -j/--junk-session-cookies ignore session cookies

  - interface <interface> specify network interface/address using

  -krb4 <level> enable krb4 with specified security level

  -j/--junk-session-cookies read file to ignore session cookies

  --interface <interface> use specified network interface/address

  --krb4 <level> use krb4 with specified security level

  -k/--insecure allow to read to SSL site without certificate -K/   --

  config specified configuration file-

l/--list-only List the file names in the ftp directory

  --limit-rate <rate> Set the transmission speed

  --local-port<NUM> Force the use of the local port number

  -m/--max-time <seconds> set maximum transfer time

  --max-redirs <num> set maximum number of directories to read

  --max-filesize <bytes> set maximum total downloaded files
-M/--manual show full manual

  -n/--netrc from Read username and password from netrc file

  --netrc-optional use .netrc or URL to override -n

  --ntlm use HTTP NTLM authentication

  -N/--no-buffer disable buffered output

  -o/--output write output to this file

  -O/--remote-name write output to this file, keep the filename of the remote file

  -p/--proxytunnel use HTTP proxy

  --proxy-anyauth choose any proxy authentication method

  --proxy-basic use basic authentication

  on proxy --proxy-digest use digital authentication

  on proxy --proxy-ntlm use ntlm authentication on proxy

  -P /--ftp-port <address> use port address instead of PASV

  -Q/--quote <cmd> before file transfer, send command to server

  -r/--range <range> retrieve from HTTP/1.1 or FTP server byte range

  --range-file random file to read (SSL)

  -R/--remote-time keep remote file time when generating file locally

  --retry <num> number of retries in case of transfer problems

  --retry-delay <seconds> When there is a problem with the transmission, set the retry interval time

  --retry-max-time <seconds> When there is a problem with the transmission, set the maximum retry time

  -s/--silent silent mode. output nothing

  -S/--show-error show error

  --socks4 <host[:port]> proxy the given host and port

  with socks4 --socks5 <host[:port]> proxy the given host and port with socks5

  --stderr <file>

  -t/--telnet-option <OPT=val> Telnet option setting

  --trace <file> debug the specified file

  --trace-ascii <file> Like --trace but no hex output

  --trace-time trace/ For verbose output, add timestamp

  -T/--upload-file <file> upload file

  --url <URL> Spet URL to work with

  -u/--user <user[:password]> set server user and password

  -U/--proxy-user <user[:password]> set proxy username and password

  -v/--verbose

  -V/--version show version info

  -w/--write-out [format] what output after completion

  -x/--proxy <host[:port]> Use HTTP proxy on given port

  -X/--request <command> specify what command

  -y/--speed-time Time to give up speed limit. The default is 30

  -Y/--speed-limit stop the limit of transmission speed, speed time' seconds

  -z/--time-cond set transmission time

  -0/--http1.0 use HTTP 1.



  -2/--sslv2 use SSLv2 (SSL)

  -3/--sslv3 use SSLv3 (SSL)

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

  --3p-url use url, do the first Three- party transmission

  --3p-user use username and password for third-party transmission

  -4/--ipv4 use IP4

  -6/--ipv6 use IP6

  -#/--progress-bar Show the current transmission status with a progress bar

  Two , Commonly used curl instance

  1, grab page content into a file

  [root@krlcgcms01 mytest]# curl -o home.html http://www.jb51.net

  [root@krlcgcms01 mytest]# curl -o home.html http: //www.jb51.net

  2, use -O (uppercase), the following url should be specific to a certain file, otherwise it will not be caught. We can also use regularity to grab things

  [root@krlcgcms01 mytest]# curl -O

  [root@krlcgcms01 mytest]# curl -O

  3, simulate form information, simulate login, save cookie information

  [root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://www.jb51.net/wp-login.php

  [root@krlcgcms01 mytest ]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://www.jb51.net/wp-login.php

  4, simulate form information, simulate login, save Header information

  [root@krlcgcms01 mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://www.jb51.net/wp-login.php

  [root@ krlcgcms01 mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** http://www.jb51.net/wp-login.php

  -c (lowercase) cookie generated It is different from the cookie in -D.

  5. Use cookie file

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt http://www.jb51.net/wp-admin

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt http: //www.jb51.net/wp-admin

  6, breakpoint resume, -C (uppercase)

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

  7, send data, it is best to use the login page to test, because after you pass the value, curl returns the data, you can see if you pass the value successfully

  [root@krlcgcms01 mytest]# curl -d log=aaaa http://www.jb51.net/wp-login.php

  [root@krlcgcms01 mytest]# curl -d log=aaaa http://www.jb51.net/wp-login .php

  8, showing a crawl error, the following example clearly shows it.

  [root@krlcgcms01 mytest]# curl -f http://www.jb51.net/asdf

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

  [root@krlcgcms01 mytest]# curl http://www.jb51.net /asdf

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

  . . . . . . . . . . . .

  [root@krlcgcms01 mytest]# curl -f http://www.jb51.net/asdf

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

  [root@krlcgcms01 mytest]# curl http://www.jb51.net /asdf

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

  . . . . . . . . . . . .

  9. Forge the source address, some websites will judge and request the source address.

  [root@krlcgcms01 mytest]# curl -e http://localhost http://www.jb51.net/wp-login.php

  [root@krlcgcms01 mytest]# curl -e http://localhost http://www .jb51.net/wp-login.php

  10, when we often use curl to do other people's things, people will block your IP, at this time, we can use the proxy

  [root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html http://www.jb51.net

  [root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html http://www.jb51.net
11. For larger things, we can download them in sections

  [root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1

  http://www.jb51.net/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://www.jb51.net/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     57      0  0:00:01  0:00:01 --:--:--     0

  [root@krlcgcms01 mytest]# curl -r 200- -o img.part3 http://www.jb51.net/wp-

  content/uploads/2010/09/compare_varnish.jpg

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

  Dload  Upload   Total   Spent    Left  Speed

  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

  [root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1 http://www.jb51.net/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://www.jb51.net/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     57      0  0:00:01  0:00:01 --:--:--     0

  [root@krlcgcms01 mytest]# curl -r 200- -o img.part3 http://www.jb51.net/wp-

  content/uploads/2010/09/compare_varnish.jpg

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

  Dload  Upload   Total   Spent    Left  Speed

  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

  When

  using, just cat them, cat img.part* >img. jpg

  12, the download progress information will not be displayed

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

  13, the download progress bar will be displayed

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

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

  14, download files via ftp

  [zhangy@BlackGhost ~]$ curl -u username:password -O http://www.jb51.net/demo/ curtain/bbstudy_files/style.css

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

  Dload Upload Total Spent Left Speed

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

  [zhangy@BlackGhost ~]$ curl -u username:password -O http ://www.jb51.net/demo/curtain/bbstudy_files/style.css

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

  Dload Upload Total Spent Left Speed

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

  or use the following method

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

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

  15, upload via ftp

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

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326481871&siteId=291194637