c# - 连接到 FTP 并搜索 .txt 中的文件

标签 c# ftp ftp-server

我正在尝试制作一个程序,让您检查该 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/

相关文章:

c# - 根据需要传递给 chromedriver 功能Capabilities c#

c# - 将 orderby、Skip() 和 Take() 与 LINQ 一起使用时出现重复行

linux - ftp 将更改的文件推送到服务器

android - 如何在不在 android 中下载的情况下从 ftpserver 播放媒体?

java - Ftp 客户端无法使用 IPV6 传输文件

java - Java中文件传输的FTP客户端服务器模型

c# - 具有非空字段的 Mongo C# 驱动程序上的聚合不过滤

c# - ASP.NET MVC - 默认范围验证错误消息未被覆盖

ubuntu proftpd [5291] : warning: unable to determine IP address of

java - 正确检查 FTP 服务器连接