如何从源构建最新的 curl 以允许通过 sftp 下载文件?

如何从源构建最新的 curl 以允许通过 sftp 下载文件?

我需要从 sftp 服务器下载文件。不幸的是,Ubuntu 中的 curl 版本

7.58.0-2ubuntu3.6 amd64

不支持sftp

我收到错误消息

Protocol "sftp" not supported or disabled in libcurl

尝试下载文件时。因此,我想curl从源代码构建以允许 sftp。我该如何实现?

答案1

注意:从第三方来源安装软件存在安全风险。在执行以下步骤之前,请确保您信任这些来源。


首先,你需要已安装。

你需要一个 tarball,例如

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

通过以下方式提取并安装:

cd libssh2-1.8.1
./configure
make
sudo make install

其次,确保卸载现有的 curl:

sudo apt purge curl

我读到过还建议卸载 curl 库,例如libcurl3-gnutls,但我注意到它有许多我不想丢失的依赖项,所以我保留了它。因此,卸载过程要小心。

第三,为了curl从源头构建、克隆curl项目:

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

我使用提交哈希对其进行了编译b8f760319668548d93ab0c023633293514d8137,如果您对当前版本遇到问题,请记住这一点master

该存储库包含GIT-INFO文件包含有关如何构建它的有用信息,并且查看它可能会很有用,因为该过程将来可能会发生变化。

对我有用的是通过以下方式构建它:

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

curl支持通过卸载sudo make uninstall。如果您遇到问题或想尝试不同的标志,这很有用。)

我没有使用共享库,因为我注意到 curl 在查找某些 curl 自己的命令时遇到问题并在尝试运行它时失败,例如我看到如下错误:

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

然而,通过上面提到的方法,我现在有一个支持 sftp 的 curl,因为 sftp 出现在支持的协议中:

$ 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

我可以确认它从 sftp 服务器下载文件。


资料来源:我通过以下途径找到了必要的步骤:

相关内容