List only files and Last Modify Date of a FTP serv

2019-08-01 04:21发布

问题:

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

回答1:

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



回答2:

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



回答3:

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.



标签: c# .net ftp