我试图创建一个程序,让您检查该ftp服务器上特定文件扩展的可用性,然后对那些已打开文件的文件进行排序。
这就是我到目前为止尝试这样做的方式:
string path;
path = "ftp://" + textBox1.Text + "/";
string[] files = System.IO.Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
答案 0 :(得分:3)
FtpWebRequest ftpRequest =
(FtpWebRequest)WebRequest.Create("ftp://ftp.freebsd.org/pub/FreeBSD/");
ftpRequest.Credentials = new NetworkCredential("anonymous", "k3rnel31@k.com");
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
List<string> filestxt = new List<string>();
string line = streamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
if (line.Contains(".txt"))
{
MessageBox.Show(line);
line = streamReader.ReadLine();
filestxt.Add(line);
}
else
{
line = streamReader.ReadLine();
}
}
streamReader.Close();