Curl: Difference between revisions

102 bytes removed ,  2 years ago
(→‎Switches: headers)
 
(4 intermediate revisions by the same user not shown)
Line 61:
</div>
 
= One-Liners =
 
Save the output of the URL to a file curl -o website.html <nowiki>https://domain.com</nowiki>
* Save the output of the URL to a file
curl -o archive.zip <nowiki>https://domain.com</nowiki>/file.zip
curl -o website.html <nowiki>https://domain.com</nowiki> > website.html
Save with name same as remote file curl -Oo archive.zip <nowiki>https://domain.com</nowiki>/file.zip
curl -O <nowiki>https://domain.com</nowiki>/file.zip -O> <nowiki>https://domain.com</nowiki>/file2website.ziphtml
 
Download files securely via SSH curl -u user <nowiki>sftp://server.domain.com/path/to/file</nowiki>
* Save with name same as remote file
curl -u username:password <nowiki>https://domain.com</nowiki>
Get HTTP header information curl -IO <nowiki>httphttps://domain.com</nowiki>file.zip
Access an FTP server curl <nowiki>ftp-O https://ftp.domain.com</nowiki>file.zip --userO usernamehttps:password//domain.com/file2.zip
 
Download a file via FTP curl <nowiki>ftp://ftp.domain.com/</nowiki>file.zip --user username:password
* Download files securely via SSH
curl -u ftpuser:password -O <nowiki>ftp://ftp_pub/public_html/index.html</nowiki>
Upload a file to the FTP server curl -Tu file.zipuser <nowiki>ftpsftp://ftpserver.domain.com/<path/nowiki> --user username:passwordto/file
curl -u username:password <nowiki>https://domain.com</nowiki>
curl -u ftpuser:password -T linuxtechi.txt <nowiki>ftp://ftp_pub/public_html/</nowiki>
 
To upload multiple files to FTP server curl -u ftpuser:password -T "(linuxtechi1.txt linuxtechi2.txt)" <nowiki>ftp://ftp_pub/public_html/</nowiki>
* Get HTTP header information
Deleting files from ftp server curl <nowiki>ftp://ftp_pub/public_html</nowiki> -X 'DELE linuxtechi.zip' --user ftpuser:password
Handle URL redirects curl -LI <nowiki>http://domain.com</nowiki>
 
Debug level details curl -v <nowiki>http://domain.com</nowiki>
* Access an FTP server
Using proxy to download a file curl -x proxy.server.com:3128 <nowiki>https://domain.com</nowiki>
curl ftp://ftp.domain.com --user username:password
Limit data transfer rate curl --limit-rate 1024B -O <nowiki>https://domain.com</nowiki>
 
Download file modified after a given date curl -z 1-Jan-17 <nowiki>https://domain.com</nowiki>
* Download a file via FTP
Download file modified before a given date curl -z -1-Jan-17 <nowiki>https://domain.com</nowiki>
Download a file via FTP curl <nowiki>ftp://ftp.domain.com/</nowiki>file.zip --user username:password
Resume a download curl -C <nowiki>https://domain.com</nowiki>
curl -u ftpuser:password -O <nowiki>ftp://ftp_pub/public_html/index.html</nowiki>
Verifying SSL certificate curl --cacert new-ca.crt <nowiki>https://domain.com</nowiki>
 
Ignoring the ssl certificate warning curl -k <nowiki>https://domain.com</nowiki>
* Upload a file to the FTP server
curl -T file.zip ftp://ftp.domain.com/ --user username:password
curl -u ftpuser:password -T linuxtechi.txt <nowiki>ftp://ftp_pub/public_html/</nowiki>
 
* To upload multiple files to FTP server
To upload multiple files to FTP server curl -u ftpuser:password -T "(linuxtechi1.txt linuxtechi2.txt)" <nowiki>ftp://ftp_pub/public_html/</nowiki>
 
* Deleting files from ftp server
Deleting files from ftp server curl <nowiki>ftp://ftp_pub/public_html</nowiki> -X 'DELE linuxtechi.zip' --user ftpuser:password
 
* Handle URL redirects
curl -L http://domain.com
 
* Debug level details
curl -v http://domain.com
 
* Using proxy to download a file
Using proxy to download a file curl -x proxy.server.com:3128 <nowiki>https://domain.com</nowiki>
 
* Limit data transfer rate
Limit data transfer rate curl --limit-rate 1024B -O <nowiki>https://domain.com</nowiki>
 
* Download file modified after a given date curl -z 1-Jan-17 <nowiki>https://domain.com</nowiki>
curl -z 1-Jan-17 https://domain.com
 
* Download file modified before a given date curl -z -1-Jan-17 <nowiki>https://domain.com</nowiki>
curl -z -1-Jan-17 https://domain.com
 
* Resume a download
curl -C https://domain.com
 
* Verifying SSL certificate
Verifying SSL certificate curl --cacert new-ca.crt <nowiki>https://domain.com</nowiki>
 
* Ignoring the ssl certificate warning curl -k <nowiki>https://domain.com</nowiki>
curl -k https://domain.com
 
* Getting information about supported methods
curl -i -X OPTIONS http://10.107.88.68:8082
 
= Scripts =
 
* Testing Response Times:
while true; do curl -s -w 'Testing Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnectTime:\t\t%{time_connect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://google.com ; sleep 10; done
 
=URL syntax=
Line 275 ⟶ 319:
Other Examples
curl -L -H "Host: aman.info.tm" -H "Cache-Control: max-age=0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "HTTPS: 1" -H "DNT: 1" -H "Referer: https://www.google.com/" -H "Accept-Language: en-US,en;q=0.8,en-GB;q=0.6,es;q=0.4" -H "If-Modified-Since: Thu, 23 Jul 2015 20:31:28 GMT" --compressed https://aman.info.tm
 
curl -L -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" https://aman.info.tm