c# - 如何在 C# 中使用 FtpWebRequest 设置端口号?

标签 c# ftp

我使用以下代码连接 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/

相关文章:

c# - 使用 Linq Select 创建新的继承对象

Java FTP上传创建一个空文件

python - 从 FTP 下载文件时出现多处理错误

c# - 如何使用反射调用带有 ref/out 参数的方法

image - 上传的 FTP 文件不反射(reflect)在网站上

java - 如何从FTP读取文件而不下载它们?

linux - vsftp虚拟用户设置配置

c# - 在 .NET 4.5 中使用 HttpClient 进行编码

c# - Rhino Mock stub 返回与预期不同的类型并破坏了我的单元测试

c# - TFS 找不到路径的一部分