Tag Archives: curl

sftp support for curl in Ubuntu 12.10 (Quantal Quetzal) and later

The Problem

Recently, downloading a file with curl via sftp failed with the error message

Protocol sftp not supported or disabled in libcurl

Indeed, as a curl -V revealed,

curl 7.27.0 (x86_64-pc-linux-gnu) libcurl/7.27.0 OpenSSL/1.0.1c zlib/1.2.7 libidn/1.25 librtmp/2.3 
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp

sftp support is lacking in Ubuntu 12.10 (Quantal Quetzal).

Searching the web indicates that this problem has been bugging Ubuntu users for several years now. The reason is that package libssh2-1 (sftp is ftp tunneled over SSH) is in universe and not in main (cf. debian/changelog). With curl being in main, it must not depend on libssh2-1.

The Solution

Nevertheless, it is possible to let curl support sftp by compiling it yourself from Ubuntu’s source package. We will describe the necessary steps shortly.

Make sure you have the appropriate deb-src entries in /etc/apt/sources.list

deb-src http://archive.ubuntu.com/ubuntu/ oneiric main restricted universe

Then, setup the build environment with

mkdir /tmp/curl
cd /tmp/curl
sudo apt-get update
sudo apt-get install build-essential debhelper libssh2-1-dev
apt-get source curl
sudo apt-get build-dep curl

Having libssh2-1-dev installed, sftp support will automatically be compiled in. You will find older tutorials that require editing debian/rules. I found this not to be necessary with recent source packages. In fact it seems the explicit disabling of libssh support by configuring with –without-libssh2 has been dropped from the rules file.

cd curl-*
dpkg-buildpackage

will build the binary packages. This will take some time, in particular the tests require you to be patient. Finally, update all curl and libcurl packages on your system (there is no need to uninstall existing packages first).

cd ..
dpkg -l | grep curl
dpkg -i curl_7.27.0-1ubuntu1.1_amd64.deb 
dpkg -i libcurl3_7.27.0-1ubuntu1.1_amd64.deb
(...)

Please keep in mind that the so installed packages will not be updated automatically. You need to go through above workflow everytime you want to update curl (and have sftp support enabled).

Further note that sftp support is a feature of libcurl and not of the command-line tool curl. So if you just update curl but not the libcurl package, you will still end up with the command-line tool lacking sftp support.

Update: It is actually the tests that take up so much time. Setting

DO_TEST=no

in debian/rules before SHLIBS_VERSION= skips any tests. In order to further speed up the build process, make use of dpkg-buildpackage’s -jNUM_PROC option. It works just as for make.

Advertisements