CURL Mini Tutorial

Curl command is used to transfer files to and from a server, it supports a number of protocols like HTTP, HTTPS, FTP, FTPS, IMAP, IMAPS, DICT, FILE, GOPHER, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP etc.

Curl also supports a lot of features like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer pause & resume, etc. There are around 120 different options that can be used with curl.

To download a file using CURL from http or ftp or any other protocol, use the following command:

curl https://server.com

If curl can't identify the protocol being used, it will switch to http. We can also store the output of the command to a file with -o option or can also redirect using >:

curl https://server.com -o file.html

or

curl https://server.com > file.html

Download Multiple Files

To download two or more files with curl in a single command, we will use -O option. Complete command is,

curl -O https://server.com/file1.tar.gz -O https://server.com/file2.tar.gz

Using FTP With Curl

To browse a ftp server, use the following command,

curl ftp://file.server.com –user username:password

To download a file from the ftp server, use the following command,

curl ftp://file.server.com/file.tar.gz –user username:password -o file.tar.gz

To upload a file to the ftp server using the curl command, use the following,

curl -T file.zip ftp:/file.server.com/file_directory/ –user username:password

Resume a Paused Download

We can also pause and resume a download with curl command. To do this, we will first start the download ,

curl -O https://server.com/file1.tar.gz

Then we can pause the download using ctrl+C and to resume the download, use the -C option:

curl -C – -O https://server.com/file1.tar.gz

Sending an Email

Though you might not be using it any time soon, but none the less we can use curl command to send email. Complete command for sending an email is,

curl –url “smtps://smtp.server.com:465” –ssl-reqd –mail-from “me@myserver.com” –mail-rcpt “guy@hisserver.com” –upload-file mailcontent.txt –user “me@myserver.com:password” –insecure

Limit Download Rate

To limit the rate at which a file is downloaded, in order to avoid network choking or for some other reason, use the curl command with –limit-rate option,

curl –limit-rate 200k -O https://server.com/file.tar.gz

Show Response Headers

To only see the response header of a URL & not the complete content , we can use option -I with curl command,

curl -I https://server.com/

This will only show the headers like http protocol, Cache-control headers, content-type etc of the mentioned url.

Using HTTP Authentication

We can also use curl to open a web url that has http authentication enabled with curl using -u option. Complete command is,

curl -u user:passwd https://server.com

Using a Proxy

To use a proxy server when visiting an URL or downloading, use -x option with curl,

curl -x squid.proxy.com:3128 https://server.com

Verifying SSL Certificate

To verify a SSL certificate of an URL, use the following command,

curl –cacert ltchlb.crt https://server.com

Ignoring SSL Certificate

To ignore the SSL certificate for an URL, we can use -k option with curl command,

curl -k https://server.com
{{ message }}

{{ 'Comments are closed.' | trans }}