Nanji Mange Nanji Mange - 2 months ago 207
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("ftp://ftp.mydomain.com/websitefolder/downloadfiles/");
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
FtpWebRequest
? If so, can anybody suggest me?

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

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

Answer

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("ftp://ftp.mydomain.com:1201/websitefolder/downloadfiles/");