libcurl 支持sftp windows vs2015编译

以前用的libcurl,不支持sftp协议,所以要重编译libcurl,来支持sftp上传文件

先down下来源码 https://github.com/curl/curl

winbuild/BUILD.WINDOWS.txt里面有windows的编译方法

Once you are in the console, go to the winbuild directory in the Curl
sources:
    cd curl-src\winbuild

Then you can call nmake /f Makefile.vc with the desired options (see below).
The builds will be in the top src directory, builds\ directory, in
a directory named using the options given to the nmake call.

nmake /f Makefile.vc mode=<static or dll> <options>

where <options> is one or many of:
  VC=<6,7,8,9,10,11,12,14,15>    - VC versions
  WITH_DEVEL=<path>              - Paths for the development files (SSL, zlib, etc.)
                                   Defaults to sibbling directory deps: ../deps
                                   Libraries can be fetched at https://windows.php.net/downloads/php-sdk/deps/
                                   Uncompress them into the deps folder.
  WITH_SSL=<dll or static>       - Enable OpenSSL support, DLL or static
  WITH_NGHTTP2=<dll or static>   - Enable HTTP/2 support, DLL or static
  WITH_MBEDTLS=<dll or static>   - Enable mbedTLS support, DLL or static
  WITH_CARES=<dll or static>     - Enable c-ares support, DLL or static
  WITH_ZLIB=<dll or static>      - Enable zlib support, DLL or static
  WITH_SSH2=<dll or static>      - Enable libSSH2 support, DLL or static
  ENABLE_SSPI=<yes or no>        - Enable SSPI support, defaults to yes
  ENABLE_IPV6=<yes or no>        - Enable IPv6, defaults to yes
  ENABLE_IDN=<yes or no>         - Enable use of Windows IDN APIs, defaults to yes
                                   Requires Windows Vista or later
  ENABLE_WINSSL=<yes or no>      - Enable native Windows SSL support, defaults to yes
  GEN_PDB=<yes or no>            - Generate Program Database (debug symbols for release build)
  DEBUG=<yes or no>              - Debug builds
  MACHINE=<x86 or x64>           - Target architecture (default is x86)
  CARES_PATH=<path to cares>     - Custom path for c-ares
  MBEDTLS_PATH=<path to mbedTLS> - Custom path for mbedTLS
  NGHTTP2_PATH=<path to HTTP/2>  - Custom path for nghttp2
  SSH2_PATH=<path to libSSH2>    - Custom path for libSSH2
  SSL_PATH=<path to OpenSSL>     - Custom path for OpenSSL
  ZLIB_PATH=<path to zlib>       - Custom path for zlib

如果要支持sftp,需要WITH_SSH2,所以需要安装libssh2

安装libssh2

down源码   https://github.com/libssh2/libssh2

这玩意编译起来也挺恶心的,参照了 http://www.guoziweb.com/html/other/2018/06/13/2265.html

libssh2,依赖openssl和zlib,可以直接下载库文件,就不说了

强烈推荐链接中的第二种编译方法


cd libssh2
mkdir dll <--directory to install libssh2
mkdir build <-- directory to build
cd build
cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=../dll --build ..

完了会在build目录生成一个vs工程,打开,找到libssh2项目,x64,或者x86,编译出来就可以了,libssh2.lib,libssh2.dll都有了

 

然后就开始编译libcurl

首先新建几个目录,里面放openssl和libssh2的库和头文件,目录结构如下

然后,打开命令行

cd curl-master/winbuild
curl-master\winbuild>nmake /f Makefile.vc mode=dll MACHINE=x64 WITH_SSL=static SSL_PATH=..\openssl-x64 WITH_SSH2=static SSH2_PATH=..\libssh2-x64

然后,在builds目录,会看到这么些文件夹,里面就是编译好的库

然后到这里,就能看到dll和一个curl.exe

然后,打开cmd窗口,

cd curl-master\builds\libcurl-vc-x64-release-dll-ssl-static-ssh2-static-ipv6-sspi\bin
curl.exe -V

curl 7.65.0-DEV (x86_64-pc-win32) libcurl/7.65.0-DEV OpenSSL/1.0.2r WinIDN libssh2/1.9.0_DEV
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTPS-proxy IDN IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI

就能看到curl支持哪些协议了,sftp已经支持了

通过sftp上传文件,网上例子很多,就不展示了,官网也有很多例子 https://curl.haxx.se/libcurl/c/example.html

最后吐槽一下,windows编译东西真的太恶心了

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值