Add support for SFTP in C + + programs under Windows

Source: Internet
Author: User
Tags openssl lib

Recently, as a result of the company's requirements to all the FTP is forbidden, only with SFTP, so only in the program to add the relevant support. It's been a couple of days since I was added to Windows. The network is generally one or two words to say this support, that can, But it's really a lot of trouble. So I feel it is necessary to write down this process for people to reference, save everyone detours.


Prerequisites:

1. Visual Studio 2012
2. Statically connect All programs. Dynamic connection is troublesome, but also to Msvcrt.dll and so on together packaging, so we all use static connection.

The first to find is Libcurl,libcurl network instructions in all support, including SFTP, but later found that the bottom to OpenSSL, and later found that the light OpenSSL is not, SFTP is done by LIBSSH2, The bottom of Libssh2 is also OpenSSL, and compiling OpenSSL requires Perl to execute some scripts. So there's a need for Perl, OpenSSL, Libssh2, Libcurl.

The first step, the installation of Perl, this is the company's computer support personnel to install, want to be very simple, do not say.

Step two, compile OpenSSL

1. Download version 1.0.1m, the latest version is 1.0.2, why not? Because that requires a tool called Netwide assembler, you need to download it separately, or compile an error, even if you set the setting Opts=no-asm. The release notes are not written at all.
2. Running in the command environment of Visual Studio 2012
CD ms
Set Opts=no-asm
Perl Configure Vc-win32
Perl util\mkfiles.pl >minfo
Perl util\mk1mf.pl%opts% Vc-win32 >32.mak
Perl util\mkdef.pl Libeay > Ms\libeay32.def
Perl util\mkdef.pl Ssleay > Ms\ssleay32.def
Nmake-f 32.mak
(Refer to 32all.bat)

Step three, compile Libssh2

1. Download version 1.5.0
2. Locate LIBSSH2.DSW, double-click Open in Visual Studio
3. Select OpenSSL Lib Release
4. Add the Include directory for OpenSSL in the project properties
5. Change the/MD to/MT (MD is a dynamic connection, obviously the LIBSSH2.DSW bug)
6. Compiling

Fourth step, compile Libcurl

1. Download version 7.40.0, the latest version is 7.41.0, but cannot compile! There is no 7.40.0 connection on the webpage, so I have to leaf out it myself.
2. Copy the OpenSSL and Libssh libraries and header files to Curl-7.40.0\. \deps, renamed Libssh2.lib to Libssh2_a.lib.
3. Running in the command environment of Visual Studio 2012
nmake/f makefile.vc mode=static vc=11 with_ssl=static with_ssh2=static debug=no
4. Run Curl.exe-v in the build-out directory
Curl-v
Curl 7.40.0 (i386-pc-win32) libcurl/7.40.0 openssl/1.0.1m winidn libssh2/1.5.0
Protocols:dict file ftp FTPs Gopher HTTP HTTPS IMAP imaps LDAP POP3 pop3s RTSP
SCP sftp SMTP Smtps telnet tftp
Features:asynchdns IDN IPv6 largefile SSPI Kerberos SPNEGO NTLM SSL
Complete

Fifth step, why is there a fifth step?

It wasn't supposed to be there.
Curl_easy_setopt (Curl, Curlopt_url, url.c_str ());
URL must be static variable! Otherwise it will crash into curl inside!

This article is from the "Bluefeather" blog, make sure to keep this source http://bluefeather.blog.51cto.com/9720359/1633919

Add support for SFTP in C + + programs under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.