【发布时间】:2017-05-13 22:50:02
【问题描述】:
我有一个 C++ 应用程序,它必须上传文件。不在代理上时,FTP 上传效果很好。但是,当客户端使用代理上传时,LibCurl 无法构建好的请求。至少,我不知道如何给它正确的信息。当然,我告诉 LibCurl 代理地址,它对 HTTP 请求非常有效。但是,FTP 上传失败。我正在使用的代码:
struct curl_slist *LibcurlHeaders = NULL;
curl = curl_easy_init();
string ProxyAddress = "ProxyURL";
string JSONFileName = "dataonserver.json";
FILE* JSONFile = fopen("data.json", "rb");
if (curl) {
CurlResponse = "";
host = "ftp://host.com/" + JSONFileName;
if (ProxyAddress.length() > 0) {
curl_easy_setopt(curl, CURLOPT_PROXY, ProxyAddress.c_str());
}
curl_easy_setopt(curl, CURLOPT_URL, host.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER , 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST , 1);
LibcurlHeaders = curl_slist_append(LibcurlHeaders, "Expect:");
curl_easy_setopt(curl, CURLOPT_USERPWD, (FTPUsername + ":" + FTPPassword).c_str());
curl_easy_setopt(curl, CURLOPT_CAINFO, FilePathSSLCertificate.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, LibcurlHeaders);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_READDATA, JSONFile);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
LibcurlError(curl_easy_strerror(res), host);
}
curl_slist_free_all(LibcurlHeaders);
curl_easy_cleanup(curl);
}
fclose(JSONFile);
我得到的回应:
* timeout on name lookup is not supported
* Trying host IP...
* TCP_NODELAY set
* Connected to host (host IP) port 21 (#0)
* Server auth using Basic with user 'username@domain.com'
> PUT ftp://username@domain.com:password@domain.com/FileName HTTP/1.1
Host: domain.com:21
Authorization: Basic Q2xpZW50VXBsb2FkQGdvZmlsZXIub3JnOkNsaWVudFVwbG9hZDE=
Accept: */*
Proxy-Connection: Keep-Alive
Transfer-Encoding: chunked
220- This is the xxxx FTP proxy server.
220- My external IP address is xxxx and I have
220- a backup ftp proxy in xxxx. When setting up
220- access to 3rd parties, be sure to allow both source
220- addresses.
220-
220- All requests will come from one of the sources IP's below:
220- xxxxx (xxx Proxy)
220- xxxxx (xxx Proxy)
220-
220- To connect to a site:
220-
220- Enter the username and site name at the User: prompt.
220- For example, to log into ftp.uu.net as anonymous, you
220- would give anonymous@ftp.uu.net at the User: prompt.
220- Enter the site password at the Password: prompt.
220- If you are connecting as anonymous, give your email address.
220-
220 Type quit to disconnect.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
500 Syntax error, command unrecognized.
【问题讨论】:
标签: c++ file-upload proxy ftp libcurl