System.Net.FtpClient.FtpListItem.Parse C# (CSharp) Method

Parse() public static method

Parses a line from a file listing using the first successful match in the Parsers collection.
public static Parse ( string path, string buf, FtpCapability capabilities ) : FtpListItem
path string The source path of the file listing
buf string A line from the file listing
capabilities FtpCapability Server capabilities
return FtpListItem
        public static FtpListItem Parse(string path, string buf, FtpCapability capabilities)
        {
            if (buf != null && buf.Length > 0) {
                FtpListItem item;

                foreach (Parser parser in Parsers) {
                    if ((item = parser(buf, capabilities)) != null) {
                        // if this is a vax/openvms file listing
                        // there are no slashes in the path name
                        if (parser == (new Parser(ParseVaxList)))
                            item.FullName = path + item.Name;
                        else {
                            FtpTrace.WriteLine(item.Name);

                            // remove globbing/wildcard from path
                            if (path.GetFtpFileName().Contains("*")) {
                                path = path.GetFtpDirectoryName();
                            }

                            item.FullName = path.GetFtpPath(item.Name); //.GetFtpPathWithoutGlob();

                            // if a link target is set and it doesn't include an absolute path
                            // then try to resolve it.
                            if (item.LinkTarget != null && !item.LinkTarget.StartsWith("/")) {
                                if (item.LinkTarget.StartsWith("./"))
                                    item.LinkTarget = path.GetFtpPath(item.LinkTarget.Remove(0, 2));
                                else
                                    item.LinkTarget = path.GetFtpPath(item.LinkTarget);
                            }
                        }

                        item.Input = buf;
                        return item;
                    }
                }
            }

            return null;
        }