Esempio n. 1
0
        /// <summary>
        /// 从Unix@
        /// </summary>
        /// <param name="Record">文件信息</param>
        private FileStruct ParseFileStructFromUnixStyleRecord(string Record)
        {
            FileStruct f          = new FileStruct();
            string     processstr = Record.Trim();

            f.Flags       = processstr.Substring(0, 10);
            f.IsDirectory = (f.Flags[0] == 'd');
            processstr    = (processstr.Substring(11)).Trim();
            _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //跳过一部分
            f.Owner = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
            f.Group = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
            _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //跳过一部分
            string yearOrTime = processstr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[2];

            if (yearOrTime.IndexOf(":") >= 0)  //time
            {
                processstr = processstr.Replace(yearOrTime, DateTime.Now.Year.ToString());
            }
            f.CreateTime = DateTime.Parse(_cutSubstringFromStringWithTrim(ref processstr, ' ', 8));
            f.Name       = processstr; //最后就是名称
            return(f);
        }
Esempio n. 2
0
 /// <summary> 
 /// 从Unix@ 
 /// </summary> 
 /// <param name="Record">文件信息</param> 
 private FileStruct ParseFileStructFromUnixStyleRecord(string Record)
 {
     FileStruct f = new FileStruct();
     string processstr = Record.Trim();
     f.Flags = processstr.Substring(0, 10);
     f.IsDirectory = (f.Flags[0] == 'd');
     processstr = (processstr.Substring(11)).Trim();
     _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //跳过一部分
     f.Owner = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
     f.Group = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
     _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //跳过一部分
     string yearOrTime = processstr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[2];
     if (yearOrTime.IndexOf(":") >= 0)  //time
     {
         processstr = processstr.Replace(yearOrTime, DateTime.Now.Year.ToString());
     }
     f.CreateTime = DateTime.Parse(_cutSubstringFromStringWithTrim(ref processstr, ' ', 8));
     f.Name = processstr;   //最后就是名称
     return f;
 }
Esempio n. 3
0
 /// <summary> 
 /// 从Windows格式中返回文件信息 
 /// </summary> 
 /// <param name="Record">文件信息</param> 
 private FileStruct ParseFileStructFromWindowsStyleRecord(string Record)
 {
     FileStruct f = new FileStruct();
     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();
     DateTimeFormatInfo myDTFI = new CultureInfo("en-US", true).DateTimeFormat;
     myDTFI.ShortTimePattern = "t";
     f.CreateTime = DateTime.Parse(dateStr + " " + timeStr, myDTFI);
     if (processstr.Substring(0, 5) == "<DIR>")
     {
         f.IsDirectory = true;
         processstr = (processstr.Substring(5, processstr.Length - 5)).Trim();
     }
     else
     {
         string[] strs = processstr.Split(new char[] { ' ' }, 2);// StringSplitOptions.RemoveEmptyEntries);   // true);
         processstr = strs[1];
         f.IsDirectory = false;
     }
     f.Name = processstr;
     return f;
 }
Esempio n. 4
0
 /// <summary> 
 /// 获得文件和目录列表 
 /// </summary> 
 /// <param name="datastring">FTP返回的列表字符信息</param> 
 private List<FileStruct> GetList(string datastring)
 {
     List<FileStruct> myListArray = new List<FileStruct>();
     string[] dataRecords = datastring.Split('\n');
     FileListStyle _directoryListStyle = GuessFileListStyle(dataRecords);
     foreach (string s in dataRecords)
     {
         if (s.IndexOf("total") != 0)
         {
             if (_directoryListStyle != FileListStyle.Unknown && s != "")
             {
                 FileStruct f = new FileStruct();
                 f.Name = "..";
                 switch (_directoryListStyle)
                 {
                     case FileListStyle.UnixStyle:
                         f = ParseFileStructFromUnixStyleRecord(s);
                         break;
                     case FileListStyle.WindowsStyle:
                         f = ParseFileStructFromWindowsStyleRecord(s);
                         break;
                 }
                 if (!(f.Name == "." || f.Name == ".."))
                 {
                     myListArray.Add(f);
                 }
             }
         }
     }
     return myListArray;
 }