public void Issue549() { var raw = new List <string> { @"dr--r--r-- 1 root root 0 Game", //unknown ftp server @"-rwxrwxrwx 1 root root 13799424 Jul 11 2011 AvatarAssetPack" //aurora }; FtpListItem.Parser parser = null; var buf = raw[0]; var item = FtpListItem.Parse("/", buf, FtpCapability.NONE, out parser); Assert.IsNotNull(parser); Assert.AreEqual(item.Type, FtpFileSystemObjectType.Directory); Assert.AreEqual(item.Name, "Game"); Assert.AreEqual(item.Modified, DateTime.MinValue); Assert.AreEqual(item.Size, 0); buf = raw[1]; item = FtpListItem.Parse("/", buf, FtpCapability.NONE, out parser); Assert.IsNotNull(parser); Assert.AreEqual(item.Type, FtpFileSystemObjectType.File); Assert.AreEqual(item.Name, "AvatarAssetPack"); Assert.AreEqual(item.Modified, new DateTime(2011, 7, 11)); Assert.AreEqual(item.Size, 13799424); }
/// <summary> /// Parses a line from a file listing using the first successful match in the Parsers collection. /// </summary> /// <param name="path">The source path of the file listing</param> /// <param name="buf">A line from the file listing</param> /// <param name="capabilities">Server capabilities</param> /// <param name="matchingParser"></param> /// <returns>A FtpListItem object representing the parsed line, null if the line was /// unable to be parsed. If you have encountered an unsupported list type add a parser /// to the public static Parsers collection of FtpListItem.</returns> public static FtpListItem Parse(string path, string buf, FtpCapability capabilities, out FtpListItem.Parser matchingParser) { matchingParser = null; if (string.IsNullOrEmpty(buf)) { return(null); } foreach (var parser in Parsers) { FtpListItem item; if ((item = parser(buf, capabilities)) == null) { continue; } matchingParser = parser; PostParse(path, buf, parser, item); return(item); } return(null); }