我使用以下代码连接 FTP。
// 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();
现在,我想设置端口号,但没有任何属性来设置端口号。是否可以使用FtpWebRequest
设置端口号?如果可以的话,有人可以推荐我吗?
如果无法设置端口号。 FtpWebRequest
使用哪个端口号来连接 FTP?
更新:我说的是端口号 21 和 22。 请指导。
最佳答案
我认为端口可以是请求 URI 本身的一部分。
尝试将第一行更改为此,将 1201 替换为您要使用的端口号:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.mydomain.com:1201/websitefolder/downloadfiles/");
关于c# - 如何在 C# 中使用 FtpWebRequest 设置端口号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39528982/