FTPWebRequest Problem

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
S

Sputnik

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top