コード例 #1
0
 public static IList<DirectoryListItem> GetDirectoryList(string datastring)
 {
     try
     {
         List<DirectoryListItem> myListArray = new List<DirectoryListItem>();
         string[] dataRecords = datastring.Split('\n');
         EDirectoryListingStyle _directoryListStyle = GuessDirectoryListingStyle(dataRecords);
         foreach (string s in dataRecords)
         {
             if (_directoryListStyle != EDirectoryListingStyle.Unknown && s != "")
             {
                 DirectoryListItem f = new DirectoryListItem();
                 f.Name = "..";
                 switch (_directoryListStyle)
                 {
                     case EDirectoryListingStyle.UnixStyle:
                         f = ParseDirectoryListItemFromUnixStyleRecord(s);
                         break;
                     case EDirectoryListingStyle.WindowsStyle:
                         f = ParseDirectoryListItemFromWindowsStyleRecord(s);
                         break;
                 }
                 if (!(f == null || f.Name == "." || f.Name == ".."))
                 {
                     myListArray.Add(f);
                 }
             }
         }
         return myListArray; ;
     }
     catch (Exception ex)
     {
         throw new FTPException("Unable to parse the directory list", ex);
     }
 }
コード例 #2
0
ファイル: DirectoryListParser.cs プロジェクト: gmonk/ATSPM
        private static DirectoryListItem ParseDirectoryListItemFromWindowsStyleRecord(string record)
        {
            ///Assuming the record style as
            /// 02-03-04  07:46PM       <DIR>          Append
            DirectoryListItem f          = new DirectoryListItem();
            string            processstr = record.Trim();
            string            dateStr    = processstr.Substring(0, 8);

            processstr = (processstr.Substring(8, processstr.Length - 8)).Trim();
            string timeStr = processstr.Substring(0, 7);

            processstr     = (processstr.Substring(7, processstr.Length - 7)).Trim();
            f.CreationTime = DateTime.Parse(dateStr + " " + timeStr, CultureInfo.GetCultureInfo("en-US"));
            if (processstr.Substring(0, 5) == "<DIR>")
            {
                f.IsDirectory = true;
                processstr    = (processstr.Substring(5, processstr.Length - 5)).Trim();
            }
            else
            {
                f.IsDirectory = false;

                int i = processstr.IndexOf(' ');
                f.Size = ulong.Parse(processstr.Substring(0, i));

                processstr = processstr.Substring(i + 1);
            }
            f.Name = processstr;  //Rest is name
            return(f);
        }
コード例 #3
0
        private static DirectoryListItem ParseDirectoryListItemFromUnixStyleRecord(string record)
        {
            ///Assuming record style as
            /// dr-xr-xr-x   1 owner    group               0 Nov 25  2002 bussys

            // Mac OS X - tnftpd returns the total on the first line
            if (record.ToLower().StartsWith("total "))
            {
                return(null);
            }

            DirectoryListItem f          = new DirectoryListItem();
            string            processstr = record.Trim();

            f.Flags       = processstr.Substring(0, 9);
            f.IsDirectory = (f.Flags[0] == 'd');
            // Note: there is no way to determine here if the symlink refers to a dir or a file
            f.IsSymLink = (f.Flags[0] == 'l');
            processstr  = (processstr.Substring(11)).Trim();
            CutSubstringFromStringWithTrim(ref processstr, " ", 0);   //skip one part
            f.Owner = CutSubstringFromStringWithTrim(ref processstr, " ", 0);
            f.Group = CutSubstringFromStringWithTrim(ref processstr, " ", 0);
            f.Size  = ulong.Parse(CutSubstringFromStringWithTrim(ref processstr, " ", 0));

            string creationTimeStr = CutSubstringFromStringWithTrim(ref processstr, " ", 8);
            string dateFormat;

            if (creationTimeStr.IndexOf(':') < 0)
            {
                dateFormat = "MMM dd yyyy";
            }
            else
            {
                dateFormat = "MMM dd H:mm";
            }

            // Some servers (e.g.: Mac OS X 10.5 - tnftpd) return days < 10 without a leading 0
            if (creationTimeStr[4] == ' ')
            {
                creationTimeStr = creationTimeStr.Substring(0, 4) + "0" + creationTimeStr.Substring(5);
            }

            f.CreationTime = DateTime.ParseExact(creationTimeStr, dateFormat, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AllowWhiteSpaces);

            if (f.IsSymLink && processstr.IndexOf(unixSymLinkPathSeparator) > 0)
            {
                f.Name = CutSubstringFromStringWithTrim(ref processstr, unixSymLinkPathSeparator, 0);
                f.SymLinkTargetPath = processstr;
            }
            else
            {
                f.Name = processstr;   //Rest of the part is name
            }
            return(f);
        }
コード例 #4
0
ファイル: DirectoryListParser.cs プロジェクト: gmonk/ATSPM
        public static IList <DirectoryListItem> GetDirectoryList(string datastring)
        {
            try
            {
                List <DirectoryListItem> myListArray = new List <DirectoryListItem>();
                string[] dataRecords = datastring.Split('\n');
                EDirectoryListingStyle _directoryListStyle = GuessDirectoryListingStyle(dataRecords);
                foreach (string s in dataRecords)
                {
                    if (_directoryListStyle != EDirectoryListingStyle.Unknown && s != "")
                    {
                        DirectoryListItem f = new DirectoryListItem();
                        f.Name = "..";
                        switch (_directoryListStyle)
                        {
                        case EDirectoryListingStyle.UnixStyle:
                            f = ParseDirectoryListItemFromUnixStyleRecord(s);
                            break;

                        case EDirectoryListingStyle.WindowsStyle:
                            f = ParseDirectoryListItemFromWindowsStyleRecord(s);
                            break;
                        }
                        if (!(f == null || f.Name == "." || f.Name == ".."))
                        {
                            myListArray.Add(f);
                        }
                    }
                }
                return(myListArray);;
            }
            catch (Exception ex)
            {
                throw new FTPException("Unable to parse the directory list", ex);
            }
        }
コード例 #5
0
ファイル: DokanFtpClient.cs プロジェクト: forger/MountFTP
 internal DirectoryFileInformation(DirectoryListItem directoryListItem)
 {
     FileName = directoryListItem.Name;
     CreationTime = directoryListItem.CreationTime;
     LastAccessTime = directoryListItem.CreationTime;
     LastWriteTime = directoryListItem.CreationTime;
     IsDirectory = directoryListItem.IsDirectory;
 }
コード例 #6
0
ファイル: DokanFtpClient.cs プロジェクト: forger/MountFTP
        DirectoryFileInformation GetDirectoryFileInformation(string parentDirectory, DirectoryListItem directoryListItem)
        {
            var path = parentDirectory + directoryListItem.Name;
            var lastWriteTime = directoryListItem.IsDirectory ?
                directoryListItem.CreationTime :
                GetCachedLastWriteTime(path) ?? directoryListItem.CreationTime;

            return new DirectoryFileInformation(directoryListItem)
            {
                LastAccessTime = lastWriteTime,
                LastWriteTime = lastWriteTime,
                Length = directoryListItem.IsDirectory ? default(long) : GetCachedLength(path),
            };
        }
コード例 #7
0
        private static DirectoryListItem ParseDirectoryListItemFromUnixStyleRecord(string record)
        {
            ///Assuming record style as
            /// dr-xr-xr-x   1 owner    group               0 Nov 25  2002 bussys

            // Mac OS X - tnftpd returns the total on the first line
            if (record.ToLower().StartsWith("total "))
                return null;

            DirectoryListItem f = new DirectoryListItem();
            string processstr = record.Trim();
            f.Flags = processstr.Substring(0, 9);
            f.IsDirectory = (f.Flags[0] == 'd');
            // Note: there is no way to determine here if the symlink refers to a dir or a file
            f.IsSymLink = (f.Flags[0] == 'l');
            processstr = (processstr.Substring(11)).Trim();
            CutSubstringFromStringWithTrim(ref processstr, " ", 0);   //skip one part
            f.Owner = CutSubstringFromStringWithTrim(ref processstr, " ", 0);
            f.Group = CutSubstringFromStringWithTrim(ref processstr, " ", 0);
            f.Size = ulong.Parse(CutSubstringFromStringWithTrim(ref processstr, " ", 0));

            string creationTimeStr = CutSubstringFromStringWithTrim(ref processstr, " ", 8);
            string dateFormat;
            if(creationTimeStr.IndexOf(':') < 0)
                dateFormat = "MMM dd yyyy";
            else
                dateFormat = "MMM dd H:mm";

            // Some servers (e.g.: Mac OS X 10.5 - tnftpd) return days < 10 without a leading 0
            if (creationTimeStr[4] == ' ')
                creationTimeStr = creationTimeStr.Substring(0, 4) + "0" + creationTimeStr.Substring(5);

            f.CreationTime = DateTime.ParseExact(creationTimeStr, dateFormat, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AllowWhiteSpaces);

            if (f.IsSymLink && processstr.IndexOf(unixSymLinkPathSeparator) > 0)
            {
                f.Name = CutSubstringFromStringWithTrim(ref processstr, unixSymLinkPathSeparator, 0);
                f.SymLinkTargetPath = processstr;
            }
            else
                f.Name = processstr;   //Rest of the part is name
            return f;
        }
コード例 #8
0
        private static DirectoryListItem ParseDirectoryListItemFromWindowsStyleRecord(string record)
        {
            ///Assuming the record style as
            /// 02-03-04  07:46PM       <DIR>          Append
            DirectoryListItem f = new DirectoryListItem();
            string processstr = record.Trim();
            string dateStr = processstr.Substring(0, 8);
            processstr = (processstr.Substring(8, processstr.Length - 8)).Trim();
            string timeStr = processstr.Substring(0, 7);
            processstr = (processstr.Substring(7, processstr.Length - 7)).Trim();
            f.CreationTime = DateTime.Parse(dateStr + " " + timeStr, CultureInfo.GetCultureInfo("en-US"));
            if (processstr.Substring(0, 5) == "<DIR>")
            {
                f.IsDirectory = true;
                processstr = (processstr.Substring(5, processstr.Length - 5)).Trim();
            }
            else
            {
                f.IsDirectory = false;

                int i = processstr.IndexOf(' ');
                f.Size = ulong.Parse(processstr.Substring(0, i));

                processstr = processstr.Substring(i + 1);
            }
            f.Name = processstr;  //Rest is name
            return f;
        }
コード例 #9
0
ファイル: DirectoryListParser.cs プロジェクト: strager/NoCap
 private static DirectoryListItem ParseDirectoryListItemFromWindowsStyleRecord(string Record)
 {
     ///Assuming the record style as
     /// 02-03-04  07:46PM       <DIR>          Append
     DirectoryListItem f = new DirectoryListItem();
     string processstr = Record.Trim();
     string dateStr = processstr.Substring(0, 8);
     processstr = (processstr.Substring(8, processstr.Length - 8)).Trim();
     string timeStr = processstr.Substring(0, 7);
     processstr = (processstr.Substring(7, processstr.Length - 7)).Trim();
     f.CreationTime = DateTime.Parse(dateStr + " " + timeStr, CultureInfo.GetCultureInfo("en-US"));
     if (processstr.Substring(0, 5) == "<DIR>")
     {
         f.IsDirectory = true;
         processstr = (processstr.Substring(5, processstr.Length - 5)).Trim();
     }
     else
     {
         //string[] strs = processstr.Split(new char[] { ' ' }, true);
         //processstr = strs[1].Trim();
         processstr = processstr.Remove(0, processstr.IndexOf(' ') + 1);
         f.IsDirectory = false;
     }
     f.Name = processstr;  //Rest is name
     return f;
 }