简体   繁体   中英

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

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

在此处输入图片说明

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

When this issue occurs, reset the curl context CurlSessionHandle and re initialize it. This might work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM