Linux – Adding Support for SCP and SFTP for Curl on Linux


I've been been desperately trying to add SFTP and SCP support for Curl on my CentOS box. I found something resembling a solution here:

I followed these steps but found that when attempting to get a file via both SCP and SFTP, the connection hangs once the file has been found. I cannot fix this and cannot find an alternative solution.

I have to use Curl for a job at work and therefore cannot use another lib. Has anyone managed to successfully add support for SCP and SFTP on Curl? I have a test server setup and other protocols such as FTP work as expected.

Any help would be greatly appreciated!

Thanks in advance,

Best Solution

Although Curl does support SFTP, support isn't automatically included in the default package.

This website: provided the details which helped me add the required support for SFTP. As the site didn't work 100% for me, I've outlined the different steps taken below.

Manually downloading libssh2 didn't work for me so I used yum to install the two packages:

yum install libssh2 libssh2-devel

and then followed step two configuring Curl to install using the above libraries

The final step was to restart sshd:

service sshd restart

There you have it. Double check that SFTP is on the list of support protocols by running

curl -V

When I initially tested, Curl complained about key authentication issues, but you can force Curl to use any authentication to connect:

curl --anyauth sftp://user:passwd@ -o Test.txt

This will round robin the different supported authentication methods and let you use you login credentials instead.

I hope this helps alleviate any other headaches for people trying to achieve the same.