示例#1
0
        /// <windows解析文件结构>
        /// 从Windows格式中返回文件信息
        /// </windows解析文件结构>
        /// <param name="Record">文件信息</param>
        private FtpFileItem ParseFileStructFromWindowsStyleRecord(string Record)
        {
            FtpFileItem f          = new FtpFileItem();
            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", false).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[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);   // true);
                processstr = strs[1];
                long ll = 0;
                Int64.TryParse(strs[0], out ll);
                f.Size        = ll;
                f.IsDirectory = false;
            }
            f.Name = processstr;
            return(f);
        }
示例#2
0
        /// <summary>
        /// 获得文件和目录列表
        /// </summary>
        /// <param name="datastring">FTP返回的列表字符信息</param>
        private FtpFileItem[] GetList(string[] dataRecords)
        {
            List <FtpFileItem> myListArray         = new List <FtpFileItem>();
            FileListStyle      _directoryListStyle = GuessFileListStyle(dataRecords);

            foreach (string s in dataRecords)
            {
                if (_directoryListStyle != FileListStyle.Unknown && s != "")
                {
                    FtpFileItem f = new FtpFileItem();
                    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);
                    }
                }
            }
            myListArray.Sort(delegate(FtpFileItem x, FtpFileItem y)
            {
                return(x.CompareTo(y));
            });

            return(myListArray.ToArray());
        }
示例#3
0
        public int CompareTo(FtpFileItem f) 
        {
            var t1 = this.IsDirectory ? 1 : 0;
            var t2 = f.IsDirectory ? 1 : 0;
            if (t1 != t2)
            {
                return t2 - t1;
            }

            return this.Name.CompareTo(f.Name);
        }
示例#4
0
        public int CompareTo(FtpFileItem f)
        {
            var t1 = this.IsDirectory ? 1 : 0;
            var t2 = f.IsDirectory ? 1 : 0;

            if (t1 != t2)
            {
                return(t2 - t1);
            }

            return(this.Name.CompareTo(f.Name));
        }
示例#5
0
        /// <Unix解析文件结构>
        /// 从Unix格式中返回文件信息
        /// </Unix解析文件结构>
        /// <param name="Record">文件信息</param>
        private FtpFileItem ParseFileStructFromUnixStyleRecord(string Record)
        {
            FtpFileItem f          = new FtpFileItem();
            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);
            f.Size  = Int64.Parse(_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);
        }
示例#6
0
        public void GetFtpServerIco(ImageList il, string ftpip, string user, string pwd, ListView lv, string path)//获取服务器的图标
        {
            string[] a;
            lv.Items.Clear();
            il.Images.Clear();
            if (path.Length == 0)
            {
                a = GetFileList(ftpip, user, pwd);
            }
            else
            {
                a = GetFileList(ftpip + "/" + path.Remove(path.LastIndexOf("/")), user, pwd);
            }
            if (a != null)
            {
                var fileInfoList = GetList(a);
                var items        = new List <ListViewItem>();
                for (int i = 0; i < fileInfoList.Length; i++)
                {
                    FtpFileItem f        = fileInfoList[i];
                    string      filetype = "";
                    if (f.IsDirectory)
                    {
                        filetype = f.Name;
                    }
                    else
                    {
                        if (f.Name.IndexOf('.') != -1)
                        {
                            filetype = f.Name.Substring(f.Name.LastIndexOf("."), f.Name.Length - f.Name.LastIndexOf("."));
                        }
                        else
                        {
                            filetype = "@";
                        }
                    }
                    il.Images.Add(GetIconByFileType(filetype, true));
                    string[] info = new string[4];
                    try
                    {
                        FileInfo fi = new FileInfo(f.Name);
                        info[0] = fi.Name;
                        //info[1] = GetFileSize(f.Name, ftpip, user, pwd, path).ToString();
                        if (f.IsDirectory)
                        {
                            info[2] = "";
                            info[1] = "文件夹";
                        }
                        else
                        {
                            info[2] = (f.Size / 1024 + 1).ToString() + " KB";
                            //info[2] = (GetFileSize(f.Name, ftpip, user, pwd, path) / 1024 + 1).ToString() + " KB";
                            //info[2] = " -- KB";
                            info[1] = fi.Extension.ToString();
                        }
                        ListViewItem item = new ListViewItem(info, i);
                        //lv.Items.Add(item);
                        items.Add(item);
                    }
                    catch (ArgumentException ex)
                    {
                    }
                }

                lv.Items.AddRange(items.ToArray());
            }
        }
示例#7
0
        /// <summary>
        /// 获得文件和目录列表
        /// </summary>
        /// <param name="datastring">FTP返回的列表字符信息</param>
        private FtpFileItem[] GetList(string[] dataRecords)
        {
            List<FtpFileItem> myListArray = new List<FtpFileItem>();
            FileListStyle _directoryListStyle = GuessFileListStyle(dataRecords);
            foreach (string s in dataRecords)
            {
                if (_directoryListStyle != FileListStyle.Unknown && s != "")
                {
                    FtpFileItem f = new FtpFileItem();
                    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);
                    }
                }
            }
            myListArray.Sort(delegate(FtpFileItem x, FtpFileItem y)
            {
                return x.CompareTo(y);
            });

            return myListArray.ToArray();
        }
示例#8
0
 /// <Unix解析文件结构>
 /// 从Unix格式中返回文件信息
 /// </Unix解析文件结构>
 /// <param name="Record">文件信息</param>
 private FtpFileItem ParseFileStructFromUnixStyleRecord(string Record)
 {
     FtpFileItem f = new FtpFileItem();
     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);
     f.Size = Int64.Parse(_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;
 }
示例#9
0
 /// <windows解析文件结构>
 /// 从Windows格式中返回文件信息
 /// </windows解析文件结构>
 /// <param name="Record">文件信息</param>
 private FtpFileItem ParseFileStructFromWindowsStyleRecord(string Record)
 {
     FtpFileItem f = new FtpFileItem();
     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", false).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[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);   // true);
         processstr = strs[1];
         f.IsDirectory = false;
     }
     f.Name = processstr;
     return f;
 }