469,572 Members | 1,610 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

FTPWebRequest Problem

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 H
Sep 11 '06 #1
2 7691
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]
- mv*@spam.guard.caspershouse.com

"Ian Hannah" <Ia*******@discussions.microsoft.comwrote in message
news:0E**********************************@microsof t.com...
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 H

Sep 11 '06 #2

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

Nicholas Paldino [.NET/C# MVP] wrote:
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]
- mv*@spam.guard.caspershouse.com

"Ian Hannah" <Ia*******@discussions.microsoft.comwrote in message
news:0E**********************************@microsof t.com...
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 H
Sep 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kevin Spencer | last post: by
7 posts views Thread by jose.lopes.cruz | last post: by
2 posts views Thread by Ian Hannah | last post: by
reply views Thread by Bob Phillips | last post: by
reply views Thread by Buddy Home | last post: by
9 posts views Thread by Waldy | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.