简体   繁体   English

[c#]我无法从ftp服务器下载文件,但我可以得到文件列表

[英][c#]I cannot download the files from ftp server, but I can get list of files

Few weeks ago, I set a ftp server in aws windows.几周前,我在 aws windows 中设置了一个 ftp 服务器。 And when I tried to download files in ftp server using WebRequestMethods.Ftp.DownloadFile;当我尝试使用 WebRequestMethods.Ftp.DownloadFile 下载 ftp 服务器中的文件时; , it didnt work. ,它没有工作。 But when I tried to get file list from ftp server using WebRequestMethods.Ftp.ListDirectory, it did work, I tried to download files with passive mode, so I thought if there would be something wrong in passive mode.但是当我尝试使用 WebRequestMethods.Ftp.ListDirectory 从 ftp 服务器获取文件列表时,它确实有效,我尝试使用被动模式下载文件,所以我想在被动模式下是否会出现问题。 so I used filezilla to connect ftp server with passive mode.所以我使用filezilla以被动模式连接ftp服务器。 and it did work well.它确实运作良好。 I could see file list and upload/download files in ftp server.我可以在 ftp 服务器中看到文件列表和上传/下载文件。 so Im thinking passive mode is working well at least and it might not be the problem.所以我认为被动模式至少运作良好,它可能不是问题。

And this is the error message that I got when I try to download files from ftp server这是我尝试从 ftp 服务器下载文件时收到的错误消息

System.Net.WebException: Server returned an error: 501 Invalid number of parameters. System.Net.WebException:服务器返回错误:501 参数数量无效。

It always is this message.它总是这个消息。

and this is the part of code that I wrote for ftp download connection.这是我为 ftp 下载连接编写的部分代码。


FtpWebRequest requestFTPUploder = (FtpWebRequest)WebRequest.Create(FTP_Address);
requestFTPUploder.UsePassive = true;
requestFTPUploder.Method = WebRequestMethods.Ftp.DownloadFile;
requestFTPUploder.Credentials = new NetworkCredential(User_Name, Password);


The 'FTP_Address' is ip v4 address for connection. “FTP_Address”是用于连接的 ip v4 地址。 I didnt set DNS for my ftp server and it works well for getting list(WebrequestMethods.Ftp.ListDirectory) I added ':20' and ':21' for selection for specific port numbers.我没有为我的 ftp 服务器设置 DNS,它适用于获取列表(WebrequestMethods.Ftp.ListDirectory)我为特定端口号的选择添加了“:20”和“:21”。 And it also worked well for getting file list.它也适用于获取文件列表。 Please help.请帮忙。 Ive been struggling for this for weeks.我为此苦苦挣扎了好几个星期。

**if i wrote something wrong, sorry for that. **如果我写错了,对不起。 This is my first time to actually write something in stackoverflow.这是我第一次在 stackoverflow 中实际写一些东西。 Ive always read other people's questions.我总是阅读别人的问题。

I guess requestUploder should be requestDownloader .我猜requestUploder应该是requestDownloader Moreover WebRequest.Create() is deprecated .此外, 不推荐使用WebRequest.Create()

But anyway, try to put a look into FTP_Address variable.但无论如何,请尝试查看FTP_Address变量。 It should be named with a name like FTP_url , so it should contain the URL of the file inside the ftp server (not only the ftp server address).它应该使用类似FTP_url的名称命名,因此它应该包含 ftp 服务器内文件的 URL(不仅是 ftp 服务器地址)。

FtpWebRequest request =
    (FtpWebRequest)WebRequest.Create("ftp://ftp.server.com/folder1/folder2/file.zip");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM