我在C++项目中使用libcurl 7.37.0与远程FTP协议进行通信。C++ Libcurl:curl_easy_perform在将文件从linux系统传输到Windows远程系统时返回了错误代码
下面是代码。文件的
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,因为该远程的发送响应代码426(传输中止)到libcurl,它将28个错误代码返回给应用程序。
请检查有wirehark痕迹的图像。
源IP:18是Linux服务器&目的IP:36的Windows远程系统
这个问题是随机发生的事情。 谁能知道原因&避免这个问题的一种方法。
这不提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17926223) –
@TheDictator虽然这个答案不是很详细,但它可能包含一个有效的解决方案。没有其他答案时,请不要删除此项。 – Melebius