We use curl
as a command-line tool to create network requests. It's accessible on Windows, Linux, and Mac, making it the go-to choice for developers across all platforms. The curl
command requires minimal user interaction and is used for automation.
curl
The curl
command supports 26 protocols defined below:
In curl,
we use the DICT protocol for dictionary lookups. Here're a few examples:
curl dict://dict.org/d:educativecurl dict://dict.org/m:curlcurl dict://dict.org/show:dbcurl dict://dict.org/find:curl
In the above commands, m
is an alias for 'match,' while d
is an alias for define.
The FILE allows us to read or write local files. It doesn't support accessing files remotely.
We can access a file using a command as follows:
curl file:///path/to/file.txt
File Transfer Protocol is a way to transfer files between a client and a server. FTPS works with an additional security layer of SSL/TLS.
We can download curl
on FTP using a similar command as follows:
curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/testfile.xml" --user "testuser:testpassword" -o "C:\test\testfile.xml" --ftp-create-dirs
Gopher is used to distribute, search, and receive documents over the internet. Secure GOPHER is done over TLS.
The Hyper Text Transfer Protocol is the most widely used protocol to transfer data online and over the internet. HTTPS is a secure version of HTTP done over an SSL/TLS connection.
The simplest and the most common HTTP request is to GET
a URL. The following command returns a web page in the terminal:
curl https://curl.se
We use POP3 to retrieve emails from a server. SSL/TLS communications may be supported by the client requesting to upgrade the connection using the STLS
command.
Secure POP3 is done over an SSL/TLS connection. Such connections implicitly start out using SSL/TLS connections.
The following command can be used to list the message numbers and sizes:
curl pop3://email.example.com/
We can use the following command to download the message with index 1:
curl pop3://email.example.com/1
The Internet Message Access Protocol is used to access, control, and read emails. It can work with or without using SSL/TLS connection. However, IMAPS is done over an SSL/TLS connection.
The following command gets the mail with mail index 34
from the mailbox inbox
:
curl imap://server.example.com/inbox;MAILINDEX=34
The following command lists the mails in the mailbox saved
and provides the user and password:
curl imap://server.example.com/saved -u user:password
The Lightweight Directory Access Protocol is designed to access and maintain distributed directory information. It is a database lookup. LDAPS is the same as LDAP but is done over SSL/TLS connection.
The following is an example of LDAP usage with curl
:
curl -u USERNAME 'ldap://192.168.0.66/CN=Users,DC=training,DC=local?sAMAccountName?sub?(ObjectClass=*)'
Message Queuing Telemetry Transport is commonly used in IoT systems to interchange data, mostly involving similar devices. It's also known as the "publish-subscribe" protocol.
The following command subscribes to the temperature in the home/lounge
subject published by example.com
:
curl mqtt://example.com/home/lounge/temp
We can send the value of '25' to the home/lounge/dimmer
subject hosted by example.com
as:
curl -d 25 mqtt://example.com/home/lounge/dimmer
The Real-Time Messaging Protocol is primarily used to control audio, video, and data streaming.
The Real-Time Streaming Protocol is used to control streaming media servers.
Secure Copy Protocol is used to copy files from and to a remote SSH server. SCP isn't portable and usually works between Unix systems.
The following command is used to download a file with SCP:
curl scp://example.com/file.zip -u username
The SSH File Transfer Protocol provides access, file transfer, and file management over a reliable data stream.
The following command downloads a file using SFTP:
curl sftp://example.com/file.zip -u username
The Server Message Block provides shared access to files, printers, serial ports, and other communications between nodes on a network. SMBS is done over TLS.
Simple Mail Transfer Protocol can be used to send an email with curl. When sending SMTP, the following command-line options must be used:
We need to tell the server at least one recipient with --mail-rcpt
.
We need to tell the server the email address of the sender with --mail-from
.
The following command sends an email using the SMTP protocol:
curl smtp://email.example.com --mail-from sender@example.com --mail-rcpt \recipient@example.com --upload-file message.txt
message.txt
file contains the contents of the email.
This protocol is used for bidirectional clear-text communication and interactive text-oriented communications. It is somewhat useful to debug other protocols and services.
Try the following command, which connects your local HTTP server on port 80, and then send a request to it (manually) by entering GET/
and pressing return twice:
curl telnet://localhost:80
Trivial File Transfer Protocol allows a user to get a file from or put a file onto a remote host. Its primary uses are to get a boot image from a local network.
The following command is used to download a file from a TFTP server:
curl -O tftp://localserver/file.boot
The following command can be used to upload a file to a TFTP server:
curl -T file.boot tftp://localserver/
If we specify a URL without a protocol prefix, curl
will attempt to guess the protocol you might want to use. It will default to HTTP protocol but try other protocols based on hostname prefixes.
You can try commands using curl
on this terminal:
Free Resources