使用 libcURL 通过 HTTP 代理连接到 FTP 服务器失败

Connecting to an FTP server through an HTTP proxy with libcURL fails

我在使用 libCurl 执行 FTP 操作之前使用此代码设置 HTTP 代理地址,我尝试连接的 FTP 服务器位于互联网(S&P 的服务器)

curl_easy_setopt(m_pCURLSession, CURLOPT_PROXY, m_strProxy); //m_strProxy is a CString object having the overloading of the cast operator (const char*) so no problems here !
curl_easy_setopt(m_pCURLSession, CURLOPT_HTTPPROXYTUNNEL, 1);

相同的代码对于 HTTP 操作没有问题!

我的 HTTP 代理服务器(使用 FreeProxy 创建)在 WinSCP 上运行良好,有时在 FileZilla 上运行良好。

问题如下,如果 HTTP 代理位于另一台机器上,我会收到此 cURL 错误:

Error=55 Failed sending data to the peer

当我将 HTTP 代理放在同一台机器上时,出现了这个错误:

(Error=56 | Failure when receiving data from the peer)!

当我删除这条指令时:

curl_easy_setopt(m_pCURLSession, CURLOPT_HTTPPROXYTUNNEL, 1);

当我请求 FTP 远程目录列表时,我得到了一个奇怪的响应,我收到了一个无用的 HTML 响应....而我期待的是 file/folders 名称列表用 "\r\n" 分隔,就像我不使用代理时一样。

解决方案很简单但并不明显:首先升级到最新的 libcURL 版本,因为在旧版本中存在与 FTP 通过 HTTP 代理建立隧道相关的已知错误,然后使用此选项:

curl_easy_setopt(m_pCURLSession, CURLOPT_FTP_USE_EPSV, 0);