FTPWebRequest Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I create an MFC application in Visual Studio 6 using the following code:

CInternetSession inet_session;
CFtpConnection *ftp_connection;

ftp_connection = inet_session.GetFtpConnection( "Integration300", "guest",
"ihannah", 21,TRUE);

CString CurrentDirectory;
ftp_connection->GetCurrentDirectory(CurrentDirectory);

then the FTP connection is made and works as expected.

If I then try and use the following code (C#, Visual Studio 2005) I always
get a timeout:

// Get the object used to communicate with the server.
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(@"ftp://integration300");
request.Credentials = new NetworkCredential("guest","ihannah");
request.Proxy = null;
request.EnableSsl = false;
request.UseBinary = true;
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();

Does anyone have any idea why this is the case?

Regards
 
Ian,

You are specifying passive mode in the call to GetFtpConnection. For
the FtpWebRequest class, you should set the UsePassive property to true so
that you make the connection to the server, and not the other way around
(you are probably behind a firewall, which is why it didn't work).

Hope this helps.
 
Nicholas,

Thanks for the reply. In the call to GetFtpConnection it does not
matter if I pass TRUE or FALSE in as the final parameter - it always
works.

Likewise with the C# code setting UsePassive makes no different - it
still doesn't work.

Ian
Ian,

You are specifying passive mode in the call to GetFtpConnection. For
the FtpWebRequest class, you should set the UsePassive property to true so
that you make the connection to the server, and not the other way around
(you are probably behind a firewall, which is why it didn't work).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ian Hannah said:
If I create an MFC application in Visual Studio 6 using the following
code:

CInternetSession inet_session;
CFtpConnection *ftp_connection;

ftp_connection = inet_session.GetFtpConnection( "Integration300", "guest",
"ihannah", 21,TRUE);

CString CurrentDirectory;
ftp_connection->GetCurrentDirectory(CurrentDirectory);

then the FTP connection is made and works as expected.

If I then try and use the following code (C#, Visual Studio 2005) I always
get a timeout:

// Get the object used to communicate with the server.
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(@"ftp://integration300");
request.Credentials = new NetworkCredential("guest","ihannah");
request.Proxy = null;
request.EnableSsl = false;
request.UseBinary = true;
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();

Does anyone have any idea why this is the case?

Regards
 
Back
Top