Nanji Mange Nanji Mange - 1 year ago 517
C# Question

How to set port number using FtpWebRequest in C#?

I connect with FTP using following code.

// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("myuser", "********");

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

Now, I want to set port number but I don't get any property to set port number. Is it possible to set port number using
? If so, can anybody suggest me?

If it is not possible to set port number. which port number use by
to connect with FTP?

Updated: I am talking about port number 21 and 22.
Please guide.

Answer Source

I think the port can be part of the Request URI itself.

Try changing the first line to this, replace 1201 with port number you want to use:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download