2

我正在尝试制作一个程序,让您检查该 ftp 服务器上特定文件扩展名的可用性,然后对那些打开文件的文件进行排序。

到目前为止,这就是我尝试做到的方式:

string path;
path = "ftp://" + textBox1.Text + "/";
string[] files = System.IO.Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
4

1 回答 1

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();
于 2013-11-17T18:04:09.950 回答