使用ListDirectory从FTP服务器提取文件名 [英] Using ListDirectory to extract file name from FTP Server

查看:452
本文介绍了使用ListDirectory从FTP服务器提取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试使用以下代码集提取FTP服务器中列出的文件名:-

Hi Guys,

I am trying to extract the file names listed in a FTP server with the following set of code:-

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xxxx.xxxx.com/");
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(FtpUserName, FtpPasswor);

// exception {"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."} is thrown in following statement
FtpWebResponse response = (FtpWebResponse)request.GetResponse(); 
 
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);
reader.Close();
response.Close();
Console.Read();


推荐答案

尝试直接使用FTP命令行客户端或具有这些凭据的另一个FTP客户端直接连接.查看是否可以连接.如果不能,那么这就是您需要首先解决的问题.
Try connecting directly using the FTP command line client or another FTP client with those credentials. See if you can connect. If you cannot, then that''s what you need to fix first.


这篇关于使用ListDirectory从FTP服务器提取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆