Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new listing detail object parsed from the specified line.
        /// </summary>
        /// <param name="line">A line as returned from an FTP LIST command.</param>
        public FtpListingDetail(string line)
        {
            if (line != null)
            {
                try
                {
                    string[] fields = line.Split(null); //Split on whitespace characters
                    fields = fields.Trim();             //Remove empty elements

                    if (fields != null && fields.Length >= 9)
                    {
                        Permissions   = new UnixFilePermissions(fields[0]);
                        HardLinkCount = int.Parse(fields[1]);
                        Owner         = fields[2];
                        Group         = fields[3];
                        Size          = long.Parse(fields[4]);

                        //Parse fields as modified date.
                        string modifiedDateString = string.Empty;
                        for (int i = 5; i < 8; i++)
                        {
                            modifiedDateString += fields[i] + ' ';
                        }
                        string[] formats = { "MMM d yyyy", "MMM d HH:mm" };
                        ModifiedDate = DateTime.ParseExact(modifiedDateString, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces);

                        //Parse remaining fields as name
                        Name = string.Empty;
                        for (int i = 8; i < fields.Length; i++)
                        {
                            Name += fields[i] + ' ';
                        }
                        Name = Name.TrimEnd();

                        return; //Cave Johnson, we're done here.
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ex); Console.ResetColor();
                }
            }

            //Since we're here parsing probably failed, so just return default values and be done.
            Permissions   = new UnixFilePermissions();
            HardLinkCount = 0;
            Owner         = string.Empty;
            Group         = string.Empty;
            Size          = 0;
            ModifiedDate  = DateTime.MinValue;
            Name          = string.Empty;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new listing detail object parsed from the specified line.
        /// </summary>
        /// <param name="line">A line as returned from an FTP LIST command.</param>
        public FtpListingDetail(string line)
        {
            if (line != null)
            {
                try
                {
                    string[] fields = line.Split(null); //Split on whitespace characters
                    fields = fields.Trim(); //Remove empty elements

                    if (fields != null && fields.Length >= 9)
                    {
                        Permissions = new UnixFilePermissions(fields[0]);
                        HardLinkCount = int.Parse(fields[1]);
                        Owner = fields[2];
                        Group = fields[3];
                        Size = long.Parse(fields[4]);

                        //Parse fields as modified date.
                        string modifiedDateString = string.Empty;
                        for (int i = 5; i < 8; i++)
                        {
                            modifiedDateString += fields[i] + ' ';
                        }
                        string[] formats = { "MMM d yyyy", "MMM d HH:mm" };
                        ModifiedDate = DateTime.ParseExact(modifiedDateString, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces);

                        //Parse remaining fields as name
                        Name = string.Empty;
                        for (int i = 8; i < fields.Length; i++)
                        {
                            Name += fields[i] + ' ';
                        }
                        Name = Name.TrimEnd();

                        return; //Cave Johnson, we're done here.
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ex); Console.ResetColor();
                }
            }

            //Since we're here parsing probably failed, so just return default values and be done.
            Permissions = new UnixFilePermissions();
            HardLinkCount = 0;
            Owner = string.Empty;
            Group = string.Empty;
            Size = 0;
            ModifiedDate = DateTime.MinValue;
            Name = string.Empty;
        }