How to build the latest curl from sources to allow downloading files via sftp?

7,279

Note: Installing software from a third-party source is a safety risk. Make sure you trust the sources before following these steps.


First, you'll need libssh installed.

You'll need a tarball, e.g.

https://www.libssh2.org/download/libssh2-1.8.2.tar.gz

Extact and install it via:

cd libssh2-1.8.1
./configure
make
sudo make install

Secondly, make sure to uninstall your existing curl:

sudo apt purge curl

I have read that it is also recommended to uninstall the curl libs, e.g. libcurl3-gnutls, BUT I noticed that it has many dependencies I did not want to lose, so I kept it. So be careful about the uninstallation process.

And third, in order to build curl from the sources, clone the curl project:

$ git clone https://github.com/curl/curl.git

I compiled it with commit hash b8f760319668548d93ab0c023633293514d8137, please bear that in mind if you have problems with the current master.

That repository contains a GIT-INFO file with useful information on how to build it and it may be useful to have a look into it, as the process may change in the future.

What worked for me was to build it via:

./buildconf
./configure
./configure --disable-libcurl-option --disable-shared --with-libssh2=/usr/local 
make
sudo make install

(curl supports uninstallation via sudo make uninstall. Useful if you having problems or what to try out different flags.)

I didn't use shared libraries as I noticed that curl was having problems finding certain curl-own commands and failed when tryin to run it, e.g. I saw errors like:

curl: symbol lookup error: curl: undefined symbol: curl_url_cleanup
curl: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

Yet with the above mentioned approach I have now a working curl supporting sftp, since sftp shows up within the supported protocols:

$ curl -V
curl 7.64.1-DEV (x86_64-pc-linux-gnu) libcurl/7.64.1-DEV OpenSSL/1.1.0g zlib/1.2.11 libssh2/1.8.1
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

and I can confirm that it downloads file from sftp servers.


Sources: I found about the necessary steps via:

Share:
7,279

Related videos on Youtube

sudcha
Author by

sudcha

Updated on September 18, 2022

Comments

  • sudcha
    sudcha over 1 year

    I need to download files from a sftp server. Unfortunately, the curl version in Ubuntu

    7.58.0-2ubuntu3.6 amd64
    

    does not support sftp.

    I get the error message

    Protocol "sftp" not supported or disabled in libcurl
    

    when trying to download a file. I therefore want to build curl from source to allow sftp. How do I achieve that?

  • HenryW
    HenryW almost 5 years
    did same but i keep getting curl: symbol lookup error: curl: undefined symbol: curl_url_cleanup. when i type curl -V . PS: I use Vagrant 2.2.25 (that might be the case)
  • sudcha
    sudcha over 4 years
    I have rerun this procecdure with commit db8f760319668548d93ab0c023633293514d8137 and I now have version: curl 7.66.0-DEV (x86_64-pc-linux-gnu) libcurl/7.66.0-DEV OpenSSL/1.1.1b zlib/1.2.11 libssh2/1.8.1
  • Jos
    Jos over 3 years
    This works. Still, I have no curl package installed, so if I try e.g. sudo apt install git-ftp it wants to install curl as well. How do I prevent this?