卷发上传卡住
我正在使用Microsoft Visual Studio 2013使用Curl-7.65.0(静态)。 我有以下方法将文件上传到FTP服务器。
bool uploadFile(string sourcePath, string url, string & error)
{
FILE * file;
file = fopen(sourcePath.c_str(), "rb");
if (!file)
{
error = "Can not open source file";
return false;
}
struct stat fileInformation;
if (fstat(fileno(file), &fileInformation) != 0)
{
error = "Can not get source file information";
return false;
}
CURL * curl;
auto curlResultCode = CURLE_FAILED_INIT;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, file);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, curl_off_t(fileInformation.st_size));
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, CURLFTP_CREATE_DIR_RETRY);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3600L);
curlResultCode = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
fclose(file);
error = curl_easy_strerror(curlResultCode);
return curlResultCode != CURLE_OK ? false : true;
}
当我调用 uploadfile
带有以下参数时:
sourcePath:c:/file.zip
url:ftp:// user:[email protected]:21/files/2022/05/20/myfile.zip
I see the directories are created in the FTP server but the file is not uploading最终,我得到 curle_operation_timedout
错误。
这是来自FTP服务器(Xlight FTP服务器)的日志,
05/21/2022 17:26:29 (not login 127.0.0.1<--127.0.0.1:21) "220 Xlight FTP Server 3.5 ready..."
05/21/2022 17:26:29 (not login 127.0.0.1-->127.0.0.1:21) "USER user"
05/21/2022 17:26:29 (not login 127.0.0.1<--127.0.0.1:21) "331 Password required for user"
05/21/2022 17:26:30 (not login 127.0.0.1-->127.0.0.1:21) "PASS *****"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "230 Login OK"
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "PWD"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "257 "/""
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "CWD files"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "550 Can't change directory to "/files"."
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "MKD files"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "257 "/files/" directory created."
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "CWD files"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "250 Directory successfully changed"
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "CWD 2022"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "550 Can't change directory to "/files/2022"."
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "MKD 2022"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "257 "/files/2022/" directory created."
05/21/2022 17:26:30 (user 127.0.0.1-->127.0.0.1:21) "CWD 2022"
05/21/2022 17:26:30 (user 127.0.0.1<--127.0.0.1:21) "250 Directory successfully changed"
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "CWD 05"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "550 Can't change directory to "/files/2022/05"."
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "MKD 05"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "257 "/files/2022/05/" directory created."
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "CWD 05"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "250 Directory successfully changed"
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "CWD 20"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "550 Can't change directory to "/files/2022/05/20"."
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "MKD 20"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "257 "/files/2022/05/20/" directory created."
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "CWD 20"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "250 Directory successfully changed"
05/21/2022 17:26:31 (user 127.0.0.1-->127.0.0.1:21) "EPSV"
05/21/2022 17:26:31 (user 127.0.0.1<--127.0.0.1:21) "229 Entering Passive Mode (|||53237|)"
05/21/2022 17:26:33 (user 127.0.0.1-->127.0.0.1:21) "TYPE I"
05/21/2022 17:26:33 (user 127.0.0.1<--127.0.0.1:21) "200 Type set to I."
您可以告诉我这里有什么问题吗?
更新1: 我还添加了读取回调功能,但结果仍然相同。
size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
{
FILE *readhere = (FILE *)userdata;
curl_off_t nread;
/* copy as much data as possible into the 'ptr' buffer, but no more than
'size' * 'nmemb' bytes! */
size_t retcode = fread(ptr, size, nmemb, readhere);
nread = (curl_off_t)retcode;
fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
" bytes from file\n", nread);
return retcode;
}
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, (void *)file);
提前致谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论