我正在尝试制作一个程序,让您检查该 ftp 服务器上特定文件扩展名的可用性,然后对包含这些文件的扩展名进行排序。
到目前为止,这就是我尝试做的事情:
string path;
path = "ftp://" + textBox1.Text + "/";
string[] files = System.IO.Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
最佳答案
FtpWebRequest ftpRequest =
(FtpWebRequest)WebRequest.Create("ftp://ftp.freebsd.org/pub/FreeBSD/");
ftpRequest.Credentials = new NetworkCredential("anonymous", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ff4acedf1faf3acaedff4b1fcf0f2" rel="noreferrer noopener nofollow">[email protected]</a>");
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();
关于c# - 连接到 FTP 并搜索 .txt 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20033784/