C++ libcurl FTP 上传通过代理不起作用
C++ libcurl FTP upload over proxy not working
我有一个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.
通常,您只能通过"隧道"通过HTTP代理进行FTP上传。您要求 libcurl 通过设置 CURLOPT_HTTPPROXYTUNNEL 选项来执行此操作。
如果没有设置该选项,libcurl 会通过代理将您的 FTP 上传转换为 HTTP PUT。
设置该选项后,libcurl 将向代理发出 CONNECT 并请求到目标服务器的隧道,然后向服务器发出"普通 FTP"命令。但是请注意,许多 HTTP 代理未设置为允许通过代理连接到 443 以外的其他端口或更多端口。很少接受典型 FTP 传输所需的端口 21。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- WinHTTP 自动代理不起作用
- C++ libcurl FTP 上传通过代理不起作用