C++ Libcurl: curl_easy_perform returned error code 28 when transferring files from linux system to windows remote system

时间:2017-08-04 12:53:38

标签: c++ linux ftp libcurl

I’m using libcurl 7.37.0 in my C++ project to communicate with remote by FTP protocol.

below is the code.

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);

many times i have observed uploading of files is failing due to error code 28.

CURLE_OPERATION_TIMEDOUT (28) Operation timeout. The specified time-out period was reached according to the conditions.

i didn't set any timeout in the code, after doing a lot of search i came to know we can use CURLOPT_TIMEOUT to set the timeout value, by default it's value is 0 where it doesn't timeout until it finishes the respective operation, in my case i performed file upload operation.

after going through the wireshark logs, i have observed that when data transfer is initiated from port 20, i see libcurl sends [FIN,ACK] without any known reason to port 21, because of that remote sends response code 426(transfer aborted) to libcurl and it returns 28 error code to application.

Please check the image which has wireshark traces.

Source IP: 18 is Linux server & Destination IP: 36 is Windows remote system

enter image description here

This problem is happening randomly. Could anyone know the reason & a way to avoid this problem.

1 个答案:

答案 0 :(得分:0)

发生此问题时,请重置curl上下文CurlSessionHandle并重新初始化它。这可能有用。