List only files and Last Modify Date of a FTP serv

2019-08-01 04:20发布

I'm trying to parse the result of the Ftp.ListDirectoryDetails command, I want just the FileName and the last modification date Not Directories.

The command returns this:

"01-21-09 06:16PM rattandom" "01-21-09 08:01PM 9900 myfile.txt"

Does somebody know the way to parse it? I was reading and if the server is Windows or Unix it will return something different. The result that I paste is for an FTP in a Windows 2003 Server

标签: c# .net ftp
3条回答
冷血范
2楼-- · 2019-08-01 04:54

There is a suggested regular exception that works on both Windows and Unix based FTP servers. See this answer.

查看更多
男人必须洒脱
3楼-- · 2019-08-01 04:59

FTP list results are non-standard so every FTP server could potentially return something different.

查看更多
手持菜刀,她持情操
4楼-- · 2019-08-01 05:10

You may want to try Ftp.dll FTP component it pareses most UNIX and Windows LIST command responses:

using (Ftp client = new Ftp())
{
    client.Connect("ftp.example.org");
    client.Login("user", "password");

    List<FtpItem> items = client.GetList();

    foreach (FtpItem item in items)
    {
        Console.WriteLine("Name:        {0}", item.Name);
        Console.WriteLine("Size:        {0}", item.Size);
        Console.WriteLine("Modify date: {0}", item.ModifyDate);

        Console.WriteLine("Is folder:   {0}", item.IsFolder);
        Console.WriteLine("Is file:     {0}", item.IsFile);
        Console.WriteLine("Is symlink:  {0}", item.IsSymlink);

        Console.WriteLine();
    }

    client.Close();
}

Please note that this is a commercial product I created.

查看更多
登录 后发表回答