In this article, I will demonstrate what is curl and how can we use curl? So, let’s begin the journey of curl.
What is Curl?
Curl is a command line tool and library. It is open source and run on various OS. Basically it is used to transferring data from a server to another server. It supports many types of Protocol like FTP, SFTP, POP3 SMB, SMTP, SMTPS, DICT, FILE, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3S, RTMP, RTSP, SCP. Curl also support SSL certificate. In today world, most of the equipment uses curl. Latest version of curl is 7.44.0 that released on 12th August 2015.
Download
You can download curl as per your Operating system compatible. It can be x86 or x64 as per your requirement. You can download it from here.
http://curl.haxx.se/download.html
There are various protocols where we can use curl. But today I will explain you how to work with FTP and SFTP using curl.
Curl with FTP
FTP, means “File Transfer Protocol, in short we use FTP, is a standard network protocol that is used to transfer the data from one host to another host over a TCP based network like Internet.
You can use following command with FTP.
Login usign curl on FTP
curl -P - --insecure "ftp://82.45.34.23:21/" --user "testuser:testpassword"
Upload using curl on FTP
curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/" --user "testuser:testpassword" -T "C:\test\testfile.xml" --ftp-create-dirs
Download using curl on FTP
curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/testfile.xml" --user "testuser:testpassword" -o "C:\test\testfile.xml" --ftp-create-dirs
Rename using curl on FTP
curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/" --user "testuser:testpassword" -Q "-RNFR /CurlPutTest/testfile.xml" -Q "-RNTO /CurlPutTest/testfile.xml.tmp" --ftp-create-dirs
Delete using curl on FTP
curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/testfile.xml" --user "testuser:testpassword" -Q "–DELE /CurlPutTest/testfile.xml" --ftp-create-dirs
Make directory using curl on FTP
Curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/test" --user "testuser:testpassword" -Q "-MKD /CurlPutTest/test" --ftp-create-dirs
Remove directory using curl on FTP
Curl -p - --insecure "ftp://82.45.34.23:21/CurlPutTest/test" --user "testuser:testpassword" -Q "-RMD /CurlPutTest/test" --ftp-create-dirs
Curl with SFTP
SFTP, means “SSH File Transfer Protocol, or “Secure File Transfer Protocol”, in short we use SFTP, is a standard network protocol that is used to transfer the data from one host to another host over a secure connection.
You can use following command with SFTP.
Login using curl on SFTP
curl -k "sftp://83.46.38.23:22/" --user "testuser:testpassword"
Upload using curl on SFTP
curl -k "sftp://83.46.38.23:22/CurlPutTest/" --user "testuser:testpassword" -T "C:\test\testfile.xml" --ftp-create-dirs
Download using curl on SFTP
curl -k "sftp://83.46.38.23:22/CurlPutTest/testfile.xml" --user "testuser:testpassword" -o "C:\test\testfile.xml" --ftp-create-dirs
Rename using curl on SFTP
curl -k "sftp://83.46.38.23:22/CurlPutTest/" --user "testuser:testpassword" -Q "-RENAME
‘/CurlPutTest/testfile.xml’ ‘/CurlPutTest/testfile.xml.tmp’" --ftp-create-dirs
Delete using curl on SFTP
curl -k "sftp://83.46.38.23:22/CurlPutTest/ " --user "testuser:testpassword" -Q "–RM /CurlPutTest/testfile.xml" --ftp-create-dirs
Make directory using curl on SFTP
curl -k "sftp://83.46.38.23:22/CurlPutTest/test " --user "testuser:testpassword" -Q "–MKDIR /CurlPutTest/Test" --ftp-create-dirs
Remove directory using curl on SFTP
curl -k "sftp://83.46.38.23:22/CurlPutTest/test " --user "testuser:testpassword" -Q "–RMDIR /CurlPutTest/Test" --ftp-create-dirs
References
http://curl.haxx.se/docs/manpage.html
Conclusion:
So, Today we learned how to use curl command line tool with ftp and sftp to transfer the file or data from local to ftp and sftp.
I hope this post will help you. Please put your feedback using comment which helps me to improve myself for next post. If you have any doubts please ask your doubts or query in the comment section and If you like this post, please share it with your friends. Thanks
Posted Comments :
bibekananda mohapatra Posted : 8 Years Ago
Hi, I need to upgrade firmware of a hardware using sftp put command . Sample command : put xxx.bin flash:force note xxx.bin is the firmware binary. How can I use this command in curl Please suggest.
Lonnie Posted : 5 Years Ago
To those who asked, and to those the author has failed to respond to apparently .. the -k switch I believe is just going to ignore certificate errors I think the Author did this out of laziness .. by adding --insecure and -k to the instructions, he makes sure it will work for more people.. however, it also could be a risk because suddenly you're at risk for man in the middle attacks or an other number of potential security problems... If you're uploading to your OWN server and you know quite well it's the right credentials.. then it's ok
ngm Posted : 5 Years Ago
I need a curl command for i wnt to go facebook/youtube live by using RTMP protocol
zhenguoli Posted : 4 Years Ago
The "curl -p - --insecure" portion in command should be "curl -P - --insecure". It should be uppercase "-P", not lowercase.
chris Posted : 3 Years Ago
This is great, thanks for sharing!
Waldemar Posted : Last Year
A big thanks.. exactly what was needed.
david Posted : Last Year
thanks, this is great article.
david Posted : Last Year
thanks, this is great article.
david Posted : Last Year
thanks, this is great article.
Stanly Posted : 9 Years Ago
If you are using the -k option for SFTP (Insecure) then the actual value of the SFTP is of no use right?? because you are accessing a SFTP server in insecure mode. How to access it in a secure mode anything additional set up we need to do for that?