Curl is a command line tool for getting or sending files using URL syntax. It is used to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. We can use curl for download files from internet, sending custom HTTP ( GET and POST ) request, as FPT client, sending e-mails etc. Curl can be used in many different and interesting ways. Some of the main features of curl is :
- User Athentication
- FTP uploading/Downloading
- FTP resume
- HTTP Post
- SSL connections
- Cookies Support
- Retry failed download ( Resume )
- Multiple URLs support
- Bandwidth limiting
- HTTP Proxy
- HTTP Resume
- HTTP persistent connections
Normally Curl comes with by-default installed in all linux based systems. But if its not installed on your system then you can easily install it by :
sudo apt-get install curl
Now below we are going some basic uses of curl utility with examples.
1. To retrieve a website :
2. Get the HTTP response header information of a website with '-I' flag
3. Download a File with curl :
4. Batch download multiple files :
8. Download file from FTP Server
9. Upload files on FTP Server
10. HTTP Authentication in Curl
1. To retrieve a website :
curl http://www.w3.org
to save the output in a file we can redirect it to a file curl http://www.w3.org > w3.html
or we can use the '-o' flag curl -o w3.html http://www.w3.org
where w3.html is output file name. By the using '-O' we can save the file with index.html name. curl -O http://www.w3.org/index.html
2. Get the HTTP response header information of a website with '-I' flag
curl -I http://www.w3.org
3. Download a File with curl :
curl -o notepadpp.exe https://notepad-plus-plus.org/repository/7.x/7.5.5/npp.7.5.5.Installer.exe
The below command will download and save the file as its same name curl -O https://notepad-plus-plus.org/repository/7.x/7.5.5/npp.7.5.5.Installer.exe
4. Batch download multiple files :
curl -O URL1 -O URL2
example :
5. Resume a Canceled Download
curl -O https://notepad-plus-plus.org/repository/7.x/7.5.5/npp.7.5.5.Installer.exe -O https://the.earth.li/~sgtatham/putty/latest/putty-0.70.tar.gz
5. Resume a Canceled Download
curl -O https://notepad-plus-plus.org/repository/7.x/7.5.5/npp.7.5.5.Installer.exe
and for some reason the download is canceled, then to resume it use '-C' flag with another '-' sign
6. Downloading a file using proxy server
curl -C - -O https://notepad-plus-plus.org/repository/7.x/7.5.5/npp.7.5.5.Installer.exe
6. Downloading a file using proxy server
Sometimes some sites are blocked in region from access, so to download files from those sites you can use the proxy servers
curl -x [proy_server] -O [file_url]
example :
7. Use Verbose mode '-v' for more information
curl -x xproxy.li.nz:3128 -O https://notepad-plus-plus.org/repository/7.x/7.5.5/npp.7.5.5.Installer.exe
7. Use Verbose mode '-v' for more information
curl -v -O https://www.w3.org/index.html
8. Download file from FTP Server
curl -u ftpuser:ftppass -O ftp://localserver/files/testc.exe
9. Upload files on FTP Server
curl -u ftpuser:ftppass -T testbin.exe ftp://localserver/
10. HTTP Authentication in Curl
Some sites are require username and password in order to access its content (which can be done by edit the .htaccess file). So at this scenario we have to provide username and password :
curl -u username:password URL
example :
Conclusion :
So these are some basic use of Curl utility. In the next post are going to see some advance usage of curl.
curl -u john:12345 http://mysecuresite.com
Conclusion :
So these are some basic use of Curl utility. In the next post are going to see some advance usage of curl.