All posts tagged SFTP

I recently did a project using cURL for PHP to SFTP files to a remote server… problem was, when I went to put the code live, SFTP wasn’t enabled in cURL. Doh! This is how I fixed it… don’t actually know if this is the “right” method, but it was tested on several servers and seemed to work well.

  • Make sure SFTP is not enabled already –

curl –version

  • If curl does not support SFTP currently we’ll build it

sudo apt-get install build-essential debhelper libssh2-1-dev
sudo apt-get source libcurl3
sudo apt-get build-dep libcurl3

cd curl-7.22.0/debian

  •  Edit the rules file to enable libssh2 support –

nano rules

– find and replace “–without-libssh2” with “–with-libssh2”

  •  Build curl with ssh support –

cd ..

sudo dpkg-buildpackage

  •  This should not be needed, but if you receive an error about missing dependencies, install them with apt-get and try to build the package again

apt-get install autoconf automake1.9 libdb-dev libgcrypt11-dev libgnutls-dev libidn11-dev libkrb5-dev libldap2-dev libnss3-dev librtmp-dev libssl-dev libtool quilt

sudo dpkg-buildpackage

  •  Install the packages you’ve built

cd ..

sudo dpkg -i curl_7.22.0-3ubuntu4_amd64.deb
sudo dpkg -i libcurl3_7.22.0-3ubuntu4_amd64.deb
sudo dpkg -i libcurl3-gnutls_7.22.0-3ubuntu4_amd64.deb

  •  Cleanup the files you’ve created –

rm -fr curl*
rm -fr libcurl*

  •  Reload Apache so the new version of cURL you have compiled is picked up by PHP –

/etc/init.d/apache2 reload

And that should be it!

You can check it’s actually enabled in PHP easily enough: