Beispiel #1
0
        // Parses a line from a Windows-format listing
        //
        // Assumes listing style as:
        // 02-03-04  07:46PM       <DIR>          Append
        protected FtpDirectoryEntry ParseWindowsDirectoryListing(string text)
        {
            FtpDirectoryEntry entry = new FtpDirectoryEntry();

            text = text.Trim();
            string dateStr = text.Substring(0, 8);

            text = text.Substring(8).Trim();
            string timeStr = text.Substring(0, 7);

            text             = text.Substring(7).Trim();
            entry.CreateTime = DateTime.Parse(String.Format("{0} {1}", dateStr, timeStr));
            if (text.Substring(0, 5) == "<DIR>")
            {
                entry.IsDirectory = true;
                text = text.Substring(5).Trim();
            }
            else
            {
                entry.IsDirectory = false;
                int pos = text.IndexOf(' ');
                entry.Size = Int64.Parse(text.Substring(0, pos));
                text       = text.Substring(pos).Trim();
            }
            entry.Name = text;  // Rest is name

            return(entry);
        }
Beispiel #2
0
        // Converts a directory listing to a list of FtpDirectoryEntrys
        protected List <FtpDirectoryEntry> ParseDirectoryListing(string listing)
        {
            ParseLine parseFunction          = null;
            List <FtpDirectoryEntry> entries = new List <FtpDirectoryEntry>();

            string[]           lines  = listing.Split('\n');
            FtpDirectoryFormat format = GuessDirectoryFormat(lines);

            if (format == FtpDirectoryFormat.Windows)
            {
                parseFunction = ParseWindowsDirectoryListing;
            }
            else if (format == FtpDirectoryFormat.Unix)
            {
                parseFunction = ParseUnixDirectoryListing;
            }

            if (parseFunction != null)
            {
                foreach (string line in lines)
                {
                    if (line.Length > 0)
                    {
                        FtpDirectoryEntry entry = parseFunction(line);
                        if (entry.Name != "." && entry.Name != "..")
                        {
                            entries.Add(entry);
                        }
                    }
                }
            }
            return(entries);;
        }
Beispiel #3
0
        // Parses a line from a UNIX-format listing
        //
        // Assumes listing style as:
        // dr-xr-xr-x   1 owner    group               0 Nov 25  2002 bussys
        protected FtpDirectoryEntry ParseUnixDirectoryListing(string text)
        {
            // Assuming record style as
            // dr-xr-xr-x   1 owner    group               0 Nov 25  2002 bussys
            FtpDirectoryEntry entry      = new FtpDirectoryEntry();
            string            processstr = text.Trim();

            entry.Flags       = processstr.Substring(0, 9);
            entry.IsDirectory = (entry.Flags[0] == 'd');
            processstr        = (processstr.Substring(11)).Trim();
            CutSubstringWithTrim(ref processstr, ' ', 0);   //skip one part
            entry.Owner = CutSubstringWithTrim(ref processstr, ' ', 0);
            entry.Group = CutSubstringWithTrim(ref processstr, ' ', 0);
            CutSubstringWithTrim(ref processstr, ' ', 0); //skip one part
            entry.CreateTime = DateTime.Parse(CutSubstringWithTrim(ref processstr, ' ', 8));
            entry.Name       = processstr;                //Rest of the part is name
            return(entry);
        }