cURL command examples
We’ll show you, 5 basic cURL example. cURL is very useful command line tool to transfer data from or to a server. cURL supports various protocols like FILE, HTTP, HTTPS, IMAP, IMAPS, LDAP, DICT, LDAPS, TELNET, FTP, FTPS, GOPHER, RTMP, RTSP, SCP, SFTP, POP3, POP3S, SMB, SMBS, SMTP, SMTPS, and TFTP. Check out our article on What is cURL?
What does cURL do?
curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction. It offers proxy support, user authentication, FTP uploading, HTTP posting, SSL connections, cookies, file transfer resume, Metalink, and many other features, listed below. cURL can be used in many different and interesting ways. With this tool you can download, upload and manage files, check your email address, or even update your status on some of the social media websites or check the weather outside. In this article will cover five of the most useful and basic uses of the cURL tool on any Linux VPS.
1. Check URL
One of the most common and simplest uses of cURL is typing the command itself, followed by the URL you want to check
This command will display the content of the URL on your terminal
2. Save the output of the URL to a file
The output of the cURL command can be easily saved to a file by adding the -o option to the command, as shown below
curl -o website https://domain.com % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 41793 0 41793 0 0 275k 0 --:--:-- --:--:-- --:--:-- 2.9M
In this example, output will be save to a file named ‘website’ in the current working directory.
3. Download files with cURL command
You can downlaod files with cURL by adding the -O option to the command. It is used for saving files on the local server with the same names as on the remote server
curl -O https://domain.com/file.zip
In this example, the ‘file.zip’ zip archive will be downloaded to the current working directory.
You can also download the file with a different name by adding the -o option to cURL.
curl -o archive.zip https://domain.com/file.zip
This way the ‘file.zip’ archive will be downloaded and saved as ‘archive.zip’.
cURL can be also used to download multiple files simultaneously, as shown in the example below
curl -O https://domain.com/file.zip -O https://domain.com/file2.zip
cURL can be also used to download files securely via SSH using the following command
curl -u user sftp://server.domain.com/path/to/file
Note that you have to use the full path of the file you want to download
4. Get HTTP header information from a website
You can easily get HTTP header information from any website you want by adding the -I option (capital ‘i’) to cURL.
curl -I http://domain.com HTTP/1.1 200 OK Date: Sun, 16 Oct 2016 23:37:15 GMT Server: Apache/2.4.23 (Unix) X-Powered-By: PHP/5.6.24 Connection: close Content-Type: text/html; charset=UTF-8
5. Access an FTP server with cURL command
To access your FTP server with cURL use the following command
curl ftp://ftp.domain.com --user username:password
cURL will connect to the FTP server and list all files and directories in user’s home directory
You can download a file via FTP
curl ftp://ftp.domain.com/file.zip --user username:password
and upload a file ot the FTP server
curl -T file.zip ftp://ftp.domain.com/ --user username:password
You can check cURL manual page to see all available cURL options and functionalities
See Also – Find Large Files in Linux
Of course, if you use one of our Linux VPS Hosting services, you can always contact and ask our expert Linux admins (via chat or ticket) about cURL commands and anything related to cURL. They are available 24×7 and will provide information or assistance immediately.
PS. If you liked this post, about cURL command examples, please share it with your friends on the social networks using the buttons below or simply leave a reply. Thanks.