2
votes

I am trying to connect to FTP server using WinGate FTP Proxy. The InternetOpen() executes successfully returning appropriate handle in all cases.

In case Proxy Authentication is OFF, InternetConnect() returns proper handle and I can proceed with further ftp operations but in case Proxy Authentication is ON, InternetConnect() returns NULL.

On MSDN they have mentioned for proxies use InternetSetOption() with INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_PASSWORD flags to set proxy username and password on handle returned by InternetConnect, but it's returning NULL and on printing GetLastError(), I get the following message:
InternetConnect failed: 12014

220 WinGate Engine FTP Gateway ready

331 send password

530 Auth Failed

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;

Any help is appreciated. Thanks in Advance.

1

1 Answers

2
votes

the problem is you are connecting to an FTP proxy, rather than an HTTP proxy. So you're getting an FTP welcome string back.

When working through a proxy using WinInet, FTP is done over HTTP. The client makes an HTTP request to the HTTP proxy for an FTP URL. the HTTP proxy acts as an FTP client to the FTP server, and translates the response back to HTTP for the client. Strange but true.

So you need to change the proxy port to be the HTTP proxy in WinGate.