【问题标题】:C++ Libcurl: curl_easy_perform returned error code 28 when transferring files from linux system to windows remote systemC ++ Libcurl:curl_easy_perform在将文件从linux系统传输到windows远程系统时返回错误代码28
【发布时间】:2017-08-04 12:53:38
【问题描述】:

我在我的 C++ 项目中使用 libcurl 7.37.0 通过 FTP 协议与远程通信。

下面是代码。

curl_easy_setopt(CurlSessionHandle, CURLOPT_URL, remoteFileUrl);
curl_easy_setopt(CurlSessionHandle, CURLOPT_UPLOAD, ON);

// Set the input local file handle
curl_easy_setopt(CurlSessionHandle, CURLOPT_READDATA, localFileHandle);

// Set on/off all wanted options
// Enable ftp data connection
curl_easy_setopt(CurlSessionHandle, CURLOPT_NOBODY, OFF);

// Create missing directory into FTP path
curl_easy_setopt(CurlSessionHandle, CURLOPT_FTP_CREATE_MISSING_DIRS , ON) ;

// Set the progress function, in order to check the stop transfer request
curl_easy_setopt(CurlSessionHandle, CURLOPT_NOPROGRESS, OFF);
curl_easy_setopt(CurlSessionHandle, CURLOPT_PROGRESSFUNCTION, progressCb);
curl_easy_setopt(CurlSessionHandle, CURLOPT_PROGRESSDATA, this);

CURLcode Result = curl_easy_perform(CurlSessionHandle);

我多次观察到由于错误代码 28 导致文件上传失败。

CURLE_OPERATION_TIMEDOUT (28) 操作超时。根据条件达到指定的超时时间。

我没有在代码中设置任何超时,经过大量搜索后我才知道我们可以使用 CURLOPT_TIMEOUT 来设置超时值,默认情况下它的值是 0 没有在完成相应操作之前不会超时,在我的情况下,我执行了文件上传操作。

查看wireshark 日志后,我观察到当从端口20 启动数据传输时,我看到libcurl 在没有任何已知原因的情况下将[FIN,ACK] 发送到端口21,因为远程向 libcurl 发送响应代码 426(传输中止),并将 28 错误代码返回给应用程序。

请检查有wireshark痕迹的图片。

源 IP:18 是 Linux 服务器和目标 IP:36 是 Windows 远程系统

这个问题是随机发生的。 谁能知道原因和避免这个问题的方法。

【问题讨论】:

    标签: c++ linux ftp libcurl


    【解决方案1】:

    出现此问题时,重置 curl 上下文 CurlSessionHandle 并重新初始化它。这可能有效。

    【讨论】:

    猜你喜欢
    • 2017-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 2017-10-02
    • 2012-10-26
    • 1970-01-01
    相关资源
    最近更新 更多