Transfers data from or to a server. Supports most protocols including HTTP, FTP, POP3.

# To download the contents of an URL to a file:
curl http://example.com -o filename

# To download a file saving the output under the filename indicated by the URL:
curl -O http://example.com/filename

# To download a file, following [L]ocation redirects, and automatically [C]ontinuing (resuming) a previous file transfer:
curl -O -L -C - http://example.com/filename

# To send form-encoded data (POST request of type application/x-www-form-urlencoded):
curl -d 'name=bob' http://example.com/form

# To send a request with an extra header using a custom HTTP method:
curl -H 'X-My-Header: 123' -X PUT http://example.com

# To send data in JSON format, specifying the appropriate content-type header:
curl -d '{"name":"bob"}' -H 'Content-Type: application/json' http://example.com/users/1234

# To pass a user name and password for server authentication and show headers info only:
curl -u myusername:mypassword -I http://example.com

# To pass client certificate and key for a secure resource:
curl -v -key key.pem -cacert ca.pem -cert client.pem -k https://example.com

# -----------------------------------------------------------------------------

# To set request headers (-v verbose):
curl -v -H "Accept: application/json" http://somehost.com/somepath/somefile

# To sequentially download numbered resources (01-24), and set the naming pattern:
curl http://example.com/files/file-[01-24].pdf -o "chapter-#1.pdf"

# To download remote resoureces using braces {..} to specify alternatives:
curl http://example.com/files/{one,two,three}.html

# To detect request directs:
curl -sI google.com | head -1 | egrep '301|302|307' | wc -l

# To create a POST request:
curl -d "item=bottle&category=consumer&submit=ok" www.example.com/process.php

# To create a HTTP Basic auth request:
curl -u username:password http://www.example.com/

# To follow redirected URL's:
curl -L http://google.com

# To specify a proxy server:
curl -U : --proxy-ntlm --proxy my-proxyserver.net:80 -O http://www.google.com/

# To set the referer:
curl -e http://some_referring_site.com  http://www.example.com/

# To set the user-agent:
curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30"

# To fetch response headers:
curl -I http://jonlabelle.com/

# To fetch response headers:
curl --head https://www.jonlabelle.com/

# To fetch response headers and body:
curl -i http://jonlabelle.com/

# To dump response headers to file:
curl --dump-header headers.txt https://www.jonlabelle.com/

# To download a file using FTP:
curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/xss.php

# To get an FTP directory listing:
curl ftp://username:password@example.com

# To get an FTP directory listing for a specific directory:
curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/

# To upload a file with FTP:
curl -T uploadfilename -u username:password ftp://sitename.com/myfile
curl -T uploadfilename -u username:password ftp://sitename.com/directory/myfile

# To get an FTP list and download files using ranges:
curl ftp://ftp.uk.debian.org/debian/pool/main/[a-z]/

# To FTP upload multiple files at a same time using ranges:
curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com

# To get user input, and save contents to ftp as `myfile_1.txt`:
curl -u ftpuser:ftppass -T - ftp://ftp.testserver.com/myfile_1.txt

# To enable a full-trace dump of all incoming/outgoing data:
curl -v --trace - http://google.com

# To specify a proxy server and download a file:
curl -x proxysever.test.com:3128 http://google.co.in

# To send mail using SMTP Protocol (note: type . (period) as the last to send):
curl --mail-from blah@test.com --mail-rcpt foo@test.com smtp://mailserver.com

# To get network info:
curl ifconfig.me        # ip
curl ifconfig.me/host   # hostname
curl ifconfig.me/ua     # user agent
curl ifconfig.me/<port> # open port check
curl ifconfig.me/all    # all

# To continue/resume a previous download:
curl -O http://www.gnu.org/software/gettext/manual/gettext.html      # ctl+c to stop the dl
curl -C - -O http://www.gnu.org/software/gettext/manual/gettext.html # continue the dl

# To limit the rate of data transfer (1000 bytes/second):
curl --limit-rate 1000B -O \
    http://www.gnu.org/software/gettext/manual/gettext.html

# To download a file if modified before/after the given date and time:
curl -z 21-Dec-11 http://www.example.com/yy.html  # if modified `later` than the given date and time
curl -z -21-Dec-11 http://www.example.com/yy.html # if modified `before` the given date and time

# To resume a failed download:
curl -C - -o partially_downloaded_file 'http://www.example.com/path/to/the/file'

# To get the population of the US (in JSON):
curl --silent 'http://api.census.gov/data/2016/pep/population?get=POP,GEONAME&for=us:*' | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[1][0]'

# To get the population of the world (in JSON):
curl --silent http://www.census.gov/popclock/data/population/world | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["world"]["population"]'

# To download all images from a 4chan thread (first grep all href images then sed the url part then wget):
curl --silent $1 | grep -o -i '<a href="//images.4chan.org/[^>]*>' | sed -r 's%.*"//([^"]*)".*%\1%' | xargs wget

# To store and reuse cookies (i.e.: for logging into web site):
curl -L -d "uid=<username>&pwd=<password>" http://www.example.com -c cookies.txt

# To debug redirects between production reloads:
#   watches the headers of a curl, following any redirects and printing only
#   the HTTP status and the location of the possible redirects
watch 'curl -s --location -I http://any.site.or.url | grep -e "\(HTTP\|Location\)"'

# To check if a web server supports gzip compression:
curl -I -H "Accept-Encoding: gzip,deflate" http://example.org

# To get the external IP and network info (as json):
curl ifconfig.me/all/json

# To download a file from SFTP:
curl -u username sftp://example.com/path/to/file.txt

# To download a file using SSH and SCP (secure copy), and a private key for authentication:
curl -u username: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub \
    scp://example.net/~/videos/rhn_register.ogv

# To get a remote resource file size in bytes:
curl -sI http://example.com/css/base.css | awk '/Content-Length/ { print $2 }'