在Windows 10 Visual Studio 2017上为FTPS设置Curl

时间:2018-07-16 13:59:26

标签: c++ windows visual-studio-2017 libcurl

我正在尝试在Windows 10的Visual Studio 2017(社区)上将Curl设置为与FTPS一起使用,但是我一直收到奇怪的错误(我尝试过的不同操作中包含的错误)。我目前有Curl在Mac上的FTPS上工作,目前在Linux上不需要它。

我尝试过的事情:

  1. 通过Curls Download Page下载二进制文件 要为MacO设置Curl,我要做的就是下载MacOs二进制文件并链接它,因此这就是我开始为Windows设置Curl的地方。但是,在下载二进制文件时,它仅包含.dll。它缺少标头和.lib文件。我尝试下载大约5个其他二进制文件,每个二进制文件都至少缺少一个基本文件。

  2. 通过vcpkg安装 无法获取二进制文件后,我意识到Curl可能位于vcpkg上。我跑了 ./vcpkg install curl来自vcpkg master。经过几分钟的编译,它成功了。然后,我去了我的项目,并通过测试ftps传输将其链接到curl。这是Curls Example page

    中的示例
    #include <stdio.h>
    
    #include <curl/curl.h>
    
    /* <DESC>
     * Get a single file from an FTP server.
     * </DESC>
     */ 
    
    struct FtpFile {
      const char *filename;
      FILE *stream;
    };
    
    static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
    {
      struct FtpFile *out = (struct FtpFile *)stream;
      if(out && !out->stream) {
       /* open file for writing */ 
         out->stream = fopen(out->filename, "wb");
        if(!out->stream)
          return -1; /* failure, can't open file to write */ 
      }
      return fwrite(buffer, size, nmemb, out->stream);
    }
    
    
    int main(void)
    {
      CURL *curl;
      CURLcode res;
      struct FtpFile ftpfile = {
        "C:\Users\myUser\Desktop\file.png", /* name to store the file as if successful */ 
        NULL
      };
    
      curl_global_init(CURL_GLOBAL_DEFAULT);
    
      curl = curl_easy_init();
      if(curl) {
        /*
         * You better replace the URL with one that works!
         */ 
        curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://my.ip.adress.here/path/to/file.png"); //Not actual address
        /* Define our callback to get called when there's data to be written */ 
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
        /* Set a pointer to our struct to pass to the callback */ 
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
    
        /* Switch on full protocol/debug output */ 
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    
        //Extra options to enable ssl (not included in example)
        curl_easy_setopt(FTPAgent,CURLOPT_USE_SSL,CURLUSESSL_ALL);
        curl_easy_setopt(FTPAgent,CURLOPT_SSL_VERIFYPEER,0L);
        curl_easy_setopt(FTPAgent,CURLOPT_USERNAME,"Username"); //Not actual username
        curl_easy_setopt(FTPAgent,CURLOPT_PASSWORD,"Password"); //Not actual password for obvious reasons
    
        res = curl_easy_perform(curl);
    
        /* always cleanup */ 
        curl_easy_cleanup(curl);
    
        if(CURLE_OK != res) {
          /* we failed */ 
          fprintf(stderr, "curl told us %d\n", res);
        }
      }
    
      if(ftpfile.stream)
        fclose(ftpfile.stream); /* close the local file */ 
    
      curl_global_cleanup();
    
      return 0;
    }
    

    该项目已编译并运行,但是在尝试下载文件时,调试控制台中出现错误,指出Curl与FTPS协议不兼容。我故意使用Explicit FTPS,因为这是我将服务器配置为接受的,并且我可以使用Mac上Curl以及Mac和Windows中FileZilla的Explicit FTPS连接到它。如果有人知道如何解决此问题,请lmk。目前我已经放弃通过vcpkg使用curl

  3. 编译源代码 我最后保存了此代码,因为我找不到用于构建Curl的任何指令,但是最终我找到了This并按照答案中的说明进行操作,其中使用curl的版本来消除除变量之外的任何变量。我在VS2017而不是VS2013上的事实。我第二次这样做时,有人请我看着它,以确保我正确地执行了所有步骤,因此,大约90%的人确定我正确地执行了这些说明。完成说明后,我使用了与上面相同的代码。它编译并运行没有错误,但是每当我尝试下载任何大小的文件时(我不确定截止值,但一个4kb的文件都能正常工作,而78kb的文件却没有),它说解密数据失败大约需要20倍的数据然后挂起:

    *   Trying my.ip.adress.here...
    * TCP_NODELAY set
    * Connected to my.ip.adress.here (my.ip.adress.here) port 21 (#0)
    < 220 (vsFTPd 2.2.2)
    > AUTH SSL
    < 234 Proceed with negotiation.
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 1/3)
    * schannel: disabled server certificate revocation checks
    * schannel: using IP address, SNI is not supported by OS.
    * schannel: sending initial handshake data: sending 147 bytes...
    * schannel: sent initial handshake data: sent 147 bytes
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 2/3)
    * schannel: failed to receive handshake, need more data
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 2/3)
    * schannel: encrypted data got 1034
    * schannel: encrypted data buffer: offset 1034 length 4096
    * schannel: a client certificate has been requested
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 2/3)
    * schannel: encrypted data buffer: offset 1034 length 4096
    * schannel: sending next handshake data: sending 349 bytes...
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 2/3)
    * schannel: encrypted data got 250
    * schannel: encrypted data buffer: offset 250 length 4096
    * schannel: SSL/TLS handshake complete
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 3/3)
    * schannel: stored credential handle in session cache
    > USER Username
    * schannel: client wants to read 16384 bytes
    * schannel: encdata_buffer resized 17408
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 85
    * schannel: encrypted data buffer: offset 85 length 17408
    * schannel: decrypted data length: 34
    * schannel: decrypted data added: 34
    * schannel: decrypted data cached: offset 34 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 34 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 34
    * schannel: decrypted data buffer: offset 0 length 16384
    < 331 Please specify the password.
    > PASS Password
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 69
    * schannel: encrypted data buffer: offset 69 length 17408
    * schannel: decrypted data length: 23
    * schannel: decrypted data added: 23
    * schannel: decrypted data cached: offset 23 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 23 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 23
    * schannel: decrypted data buffer: offset 0 length 16384
    < 230 Login successful.
    > PBSZ 0
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 69
    * schannel: encrypted data buffer: offset 69 length 17408
    * schannel: decrypted data length: 20
    * schannel: decrypted data added: 20
    * schannel: decrypted data cached: offset 20 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 20 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 20
    * schannel: decrypted data buffer: offset 0 length 16384
    < 200 PBSZ set to 0.
    > PROT P
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 69
    * schannel: encrypted data buffer: offset 69 length 17408
    * schannel: decrypted data length: 23
    * schannel: decrypted data added: 23
    * schannel: decrypted data cached: offset 23 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 23 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 23
    * schannel: decrypted data buffer: offset 0 length 16384
    < 200 PROT now Private.
    > PWD
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 53
    * schannel: encrypted data buffer: offset 53 length 17408
    * schannel: decrypted data length: 9
    * schannel: decrypted data added: 9
    * schannel: decrypted data cached: offset 9 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 9 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 9
    * schannel: decrypted data buffer: offset 0 length 16384
    < 257 "/"
    * Entry path is '/'
    > CWD path
    * ftp_perform ends with SECONDARY: 0
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 85
    * schannel: encrypted data buffer: offset 85 length 17408
    * schannel: decrypted data length: 37
    * schannel: decrypted data added: 37
    * schannel: decrypted data cached: offset 37 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 37 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 37
    * schannel: decrypted data buffer: offset 0 length 16384
    < 250 Directory successfully changed.
    > CWD to
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 85
    * schannel: encrypted data buffer: offset 85 length 17408
    * schannel: decrypted data length: 37
    * schannel: decrypted data added: 37
    * schannel: decrypted data cached: offset 37 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 37 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 37
    * schannel: decrypted data buffer: offset 0 length 16384
    < 250 Directory successfully changed.
    > EPSV
    * Connect data stream passively
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 101
    * schannel: encrypted data buffer: offset 101 length 17408
    * schannel: decrypted data length: 48
    * schannel: decrypted data added: 48
    * schannel: decrypted data cached: offset 48 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 48 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 48
    * schannel: decrypted data buffer: offset 0 length 16384
    < 229 Entering Extended Passive Mode (|||1040|).
    *   Trying my.ip.adress.here...
    * TCP_NODELAY set
    * Connecting to my.ip.adress.here (my.ip.adress.here) port 1040
    * Connected to my.ip.adress.here (my.ip.adress.here) port 21 (#0)
    > TYPE I
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 85
    * schannel: encrypted data buffer: offset 85 length 17408
    * schannel: decrypted data length: 31
    * schannel: decrypted data added: 31
    * schannel: decrypted data cached: offset 31 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 31 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 31
    * schannel: decrypted data buffer: offset 0 length 16384
    < 200 Switching to Binary mode.
    > SIZE file.png
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 53
    * schannel: encrypted data buffer: offset 53 length 17408
    * schannel: decrypted data length: 11
    * schannel: decrypted data added: 11
    * schannel: decrypted data cached: offset 11 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 11 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 11
    * schannel: decrypted data buffer: offset 0 length 16384
    < 213 84381
    > RETR file.png
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 117
    * schannel: encrypted data buffer: offset 117 length 17408
    * schannel: decrypted data length: 68
    * schannel: decrypted data added: 68
    * schannel: decrypted data cached: offset 68 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 68 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 68
    * schannel: decrypted data buffer: offset 0 length 16384
    < 150 Opening BINARY mode data connection for 001.png (84381 bytes).
    * Maxdownload = -1
    * Getting file with size: 84381
    * Doing the SSL/TLS handshake on the data stream
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 1/3)
    * schannel: re-using existing credential handle
    * schannel: incremented credential handle refcount = 3
    * schannel: using IP address, SNI is not supported by OS.
    * schannel: sending initial handshake data: sending 307 bytes...
    * schannel: sent initial handshake data: sent 307 bytes
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 2/3)
    * schannel: failed to receive handshake, need more data
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 2/3)
    * schannel: encrypted data got 129
    * schannel: encrypted data buffer: offset 129 length 4096
    * schannel: sending next handshake data: sending 75 bytes...
    * schannel: SSL/TLS handshake complete
    * schannel: SSL/TLS connection with my.ip.adress.here port 21 (step 3/3)
    * schannel: client wants to read 16384 bytes
    * schannel: encdata_buffer resized 17408
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 10220
    * schannel: encrypted data buffer: offset 10220 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 10220 length 17408
    * schannel: encrypted data got 4380
    * schannel: encrypted data buffer: offset 14600 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 14600 length 17408
    * schannel: encrypted data got 1460
    * schannel: encrypted data buffer: offset 16060 length 17408
    * schannel: decrypted data length: 15872
    * schannel: decrypted data added: 15872
    * schannel: decrypted data cached: offset 15872 length 16384
    * schannel: encrypted data length: 135
    * schannel: encrypted data cached: offset 135 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 15872
    * schannel: decrypted data buffer: offset 0 length 16384
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 135 length 17408
    * schannel: encrypted data got 16060
    * schannel: encrypted data buffer: offset 16195 length 17408
    * schannel: decrypted data length: 15872
    * schannel: decrypted data added: 15872
    * schannel: decrypted data cached: offset 15872 length 16384
    * schannel: encrypted data length: 270
    * schannel: encrypted data cached: offset 270 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 15872
    * schannel: decrypted data buffer: offset 0 length 16384
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 270 length 17408
    * schannel: encrypted data got 16060
    * schannel: encrypted data buffer: offset 16330 length 17408
    * schannel: decrypted data length: 15872
    * schannel: decrypted data added: 15872
    * schannel: decrypted data cached: offset 15872 length 16384
    * schannel: encrypted data length: 405
    * schannel: encrypted data cached: offset 405 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 15872
    * schannel: decrypted data buffer: offset 0 length 16384
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 405 length 17408
    * schannel: encrypted data got 14600
    * schannel: encrypted data buffer: offset 15005 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 15005 length 17408
    * schannel: encrypted data got 2403
    * schannel: encrypted data buffer: offset 17408 length 17408
    * schannel: decrypted data length: 15872
    * schannel: decrypted data added: 15872
    * schannel: decrypted data cached: offset 15872 length 16384
    * schannel: encrypted data length: 1483
    * schannel: encrypted data cached: offset 1483 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 15872
    * schannel: decrypted data buffer: offset 0 length 16384
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 1483 length 17408
    * schannel: encrypted data got 15925
    * schannel: encrypted data buffer: offset 17408 length 17408
    * schannel: decrypted data length: 2048
    * schannel: decrypted data added: 2048
    * schannel: decrypted data cached: offset 2048 length 16384
    * schannel: encrypted data length: 15307
    * schannel: encrypted data cached: offset 15307 length 17408
    * schannel: failed to decrypt data, need more data
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 2048
    * schannel: decrypted data buffer: offset 0 length 16384
    * schannel: client wants to read 16384 bytes
    * schannel: encrypted data buffer: offset 15307 length 17408
    * schannel: encrypted data got 2101
    * schannel: encrypted data buffer: offset 17408 length 17408
    * schannel: decrypted data length: 16384
    * schannel: decrypted data added: 16384
    * schannel: decrypted data cached: offset 16384 length 16384
    * schannel: encrypted data length: 971
    * schannel: encrypted data cached: offset 971 length 17408
    * schannel: encrypted data buffer: offset 971 length 17408
    * schannel: decrypted data buffer: offset 16384 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 16384
    * schannel: decrypted data buffer: offset 0 length 16384
    * schannel: client wants to read 2461 bytes
    * schannel: encrypted data buffer: offset 971 length 17408
    * schannel: encrypted data got 1599
    * schannel: encrypted data buffer: offset 2570 length 17408
    * schannel: decrypted data length: 2461
    * schannel: decrypted data added: 2461
    * schannel: decrypted data cached: offset 2461 length 16384
    * schannel: encrypted data length: 53
    * schannel: encrypted data cached: offset 53 length 17408
    * schannel: encrypted data buffer: offset 53 length 17408
    * schannel: decrypted data buffer: offset 2461 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 2461
    * schannel: decrypted data buffer: offset 0 length 16384
    

    同样,出于明显的原因,我用伪值替换了IP,用户名和密码。

注意:

  1. HTTPS与方法3一起使用(未在方法2中尝试过,所以我不知道它是否有效)Curl在我的服务器和Google上成功执行了https get请求。
  2. 我假设问题出在我安装的curl或我的代码上,但是可能是因为我的服务器出现问题,因为我没有其他ftps服务器对其进行测试。我知道我可以通过Mac上的Curl以及Mac和Windows上的Filezilla从服务器上执行ftps操作。
  3. 我两次尝试了方法2,两次尝试了方法3。

如果我可以提供更多信息,请告诉我。多谢您的协助。如果一周后我能完成这项工作,我将感到非常高兴。

0 个答案:

没有答案