WinINet FTP Bug with passive connection



Somewhat randomly, I am receving error 12002 (ERROR_INTERNET_TIMEOUT) from a
call to the WinINet InternetConnect function while trying to set up an FTP
session with a remote server.

In looking at a Ethereal/Wireshark trace of the network packets, my client
sends out the PASV request, the server responds with the 227 "entering
passive mode" packet, but my client never even trys to open the port
specified in the 227 message.

It isn't clear whether InternetConnect is responsible for opening the
specified port or if that would be the responsibility of the call to
FtpPutFile which follows. But no matter, as the InternetConnect returns an
error which, in my opinion, means something is wrong and I should close down
the connection.

The software firewall is disabled. I don't see how it could be a firewall
on the network causing the problem as the Wireshark trace clearly shows the
FTP server is folowing the protocol spec and it is my failure to open the
specified port.

Any thoughts?

Windows Server 2003 Standard Edition SP2


Below is the C++ code:
----------------------------
::HINTERNET iHandle = ::InternetOpen(
"TEST",
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
0 );
if ( NULL == iHandle )
{
LOG_ERROR( std::string( "Unable to access internet: " )
+ formatSystemError( ::GetLastError() ) );
}
else
{
::HINTERNET ftpSession = ::InternetConnect(
iHandle,
m_ipAddress.c_str(),
INTERNET_DEFAULT_FTP_PORT,
m_username.c_str(),
m_password.c_str(),
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE,
0 );
if ( NULL == ftpSession )
{
LOG_ERROR( formatInternetError(
"Unable to connect to FTP server (" + m_ipAddress + "):",
::GetLastError() ) );
}
else
{
std::string remoteFileName( fileName.substr( fileName.find_last_of( '\\'
) + 1 ) );
if ( !::FtpSetCurrentDirectory( ftpSession, m_targetDirectory.c_str() ) )
{
LOG_ERROR( formatInternetError(
"Unable to set default directory on remote FTP server to " +
m_targetDirectory + ":",
::GetLastError() ) );
}
else if( !::FtpPutFile(
ftpSession,
fileName.c_str(),
remoteFileName.c_str(),
INTERNET_FLAG_TRANSFER_ASCII,
0 ) )
{
LOG_ERROR( formatInternetError(
"Unable to send " + fileName + " to " + remoteFileName + " on remote
FTP server:",
::GetLastError() ) );
}
::InternetCloseHandle( ftpSession );
}
::InternetCloseHandle( iHandle );
}

.



Relevant Pages

  • Re: FrontPage API
    ... FrontPage uses the connection info / mechanism used by Internet Explorer. ... Starting an FTP Session ... The application establishes an ftp session by calling InternetConnect on a handle created by ... Enumeration of a directory on an ftp server requires the creation of a handle by FtpFindFirstFile. ...
    (microsoft.public.frontpage.programming)
  • SFTP
    ... I use the wininet API to FTP files. ... InternetConnect ... It is described as a SFTP/SSH server. ...
    (microsoft.public.vb.general.discussion)
  • Re: PLEASE HELP! URLDownloadToFile fails.
    ... moreover you can check for msdn for ftp access. ... My sanity holds in the balance, the folowing URLDownload call fails with error 0x800C0006L. ... The FTP file does exists, and correct latter case is used. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: PLEASE HELP! URLDownloadToFile fails.
    ... moreover you can check for msdn for ftp access. ... My sanity holds in the balance, the folowing URLDownload call fails with error 0x800C0006L. ... The FTP file does exists, and correct latter case is used. ...
    (microsoft.public.windowsce.embedded)
  • secure FTP client for Pocket PC/WinCE
    ... We have developed a FTP client for Pocket PC 2002 ... It is based on InternetOpen, InternetConnect, ... InternetReadFile/WriteFile, ReadFile/InternetWriteFile ... (for upload) ...
    (microsoft.public.pocketpc)