【问题标题】:InternetConnect fails to connect to FTP server via ftp proxyInternetConnect 无法通过 ftp 代理连接到 FTP 服务器
【发布时间】:2023-03-22 09:35:01
【问题描述】:

我正在尝试使用 WinGate FTP 代理连接到 FTP 服务器。 InternetOpen() 在所有情况下都成功执行并返回适当的句柄。

如果 Proxy Authentication 关闭,InternetConnect() 返回正确的句柄,我可以继续进行进一步的 ftp 操作,但如果 Proxy Authentication 关闭,InternetConnect() 返回空。

在 MSDN 上,他们提到的代理使用带有 INTERNET_OPTION_PROXY_USERNAME 和 INTERNET_OPTION_PROXY_PASSWORD 标志的 InternetSetOption() 在 InternetConnect 返回的句柄上设置代理用户名和密码,但它返回 NULL 并且在打印 GetLastError() 时,我收到以下消息:
InternetConnect 失败:12014

220 WinGate Engine FTP 网关就绪

331发送密码

530 验证失败

if ((hHandle=InternetOpen("Upload", INTERNET_OPEN_TYPE_PROXY, "ftp=ftp://<servername>:<port>", NULL, 0)) == NULL)
    {
        printf("InternetOpen failed: %d", GetLastError());
        printInternetErrorMsg(function);
        return false;   
    }   
    char buffer[1024];
    string proxy_username,proxy_password;
    // get ftp proxy username and password
            // ..


    if ((m_itConnect=InternetConnect(hHandle, ftpserver, INTERNET_DEFAULT_FTP_PORT, ftpusrname, ftppasswd, INTERNET_SERVICE_FTP, NULL, NULL)) == NULL){
        printf("InternetConnect failed: %d", GetLastError());
        printInternetErrorMsg(function);
                    //Internet Connect Fails with following error when Proxy Authentication is ON
                    //InternetConnect failed: 12014
                    //220 WinGate Engine FTP Gateway ready
                    //331 send password
                    //530 Auth Failed 

        return false;           
    }
    strcpy(buffer,proxy_username.c_str());

    if ( !InternetSetOption (m_itConnect, INTERNET_OPTION_PROXY_USERNAME, (LPVOID) buffer, lstrlen (buffer) ))
    {
        printf("Unable to set proxy authetication settings (username). Error returned: %d",  GetLastError() );
        return false;
    }

    strcpy(buffer, proxy_password.c_str());

    if ( !InternetSetOption (m_itConnect, INTERNET_OPTION_PROXY_PASSWORD, (LPVOID) buffer, lstrlen (buffer) ))
    {
        printf("Unable to set proxy authetication settings (password). Error returned: %d",  GetLastError() );
        return false;
    }
}


printf("InternetConnect successful ...");
return true;

感谢任何帮助。 提前致谢。

【问题讨论】:

    标签: c++ proxy ftp


    【解决方案1】:

    问题是您连接的是 FTP 代理,而不是 HTTP 代理。所以你会收到一个 FTP 欢迎字符串。

    当使用 WinInet 通过代理工作时,FTP 是通过 HTTP 完成的。客户端向 HTTP 代理发出 HTTP 请求以获取 FTP URL。 HTTP 代理充当 FTP 服务器的 FTP 客户端,并将响应转换回客户端的 HTTP。奇怪但真实。

    所以你需要将代理端口改为WinGate中的HTTP代理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 2021-02-03
      • 1970-01-01
      • 2015-09-21
      • 2021-03-17
      相关资源
      最近更新 更多