我在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