/// <summary> /// Get Ftp full directory list. /// </summary> /// <param name="rawString">Source string.</param> /// <param name="parentPath">Parent path string.</param> /// <returns>List of FtpFileInfo, or null if path does not exist.</returns> public static List <FtpFileInfo> GetFullDirectoryList(string rawString, string parentPath) { List <FtpFileInfo> result = new List <FtpFileInfo>(); if (string.IsNullOrEmpty(rawString)) { return(result); } string[] rawList = rawString.Split('\n'); if (rawList == null || rawList.Length < 1) { return(result); } FtpFileStyle ftpFileStyle = GetFtpFileStyle(rawList); switch (ftpFileStyle) { case FtpFileStyle.WindowsStyle: foreach (string item in rawList) { if (!string.IsNullOrEmpty(item)) { FtpFileInfo ftpFileInfo = new FtpFileInfo(); ftpFileInfo.Name = ".."; ftpFileInfo = ParseWindowsStyleFtpFile(item); ftpFileInfo.ParentDirectory = parentPath; if (ftpFileInfo != null && ftpFileInfo.Name != "." && ftpFileInfo.Name != "..") { result.Add(ftpFileInfo); } } } break; case FtpFileStyle.UnixStyle: foreach (string item in rawList) { if (!string.IsNullOrEmpty(item)) { FtpFileInfo ftpFileInfo = new FtpFileInfo(); ftpFileInfo.Name = ".."; ftpFileInfo = ParseUnixStyleFtpFile(item); ftpFileInfo.ParentDirectory = parentPath; if (ftpFileInfo != null && ftpFileInfo.Name != "." && ftpFileInfo.Name != "..") { result.Add(ftpFileInfo); } } } break; case FtpFileStyle.Unknown: default: break; } return(result); }
/// <summary> /// Get Ftp file list. /// </summary> /// <param name="rawString">Source string.</param> /// <param name="parentPath">Parent path string.</param> /// <returns>List of FtpFileInfo, or null if path does not exist.</returns> public static List <FtpFileInfo> GetFileList(string rawString, string parentPath) { List <FtpFileInfo> result = new List <FtpFileInfo>(); if (string.IsNullOrEmpty(rawString)) { return(result); } string[] rawArray = rawString.Split('\n'); if (rawArray == null || rawArray.Length < 1) { return(result); } FtpFileStyle ftpFileStyle = GetFtpFileStyle(rawArray); List <string> rawList = new List <string>(rawArray); switch (ftpFileStyle) { case FtpFileStyle.WindowsStyle: rawList.RemoveAll(delegate(string item) { return(item.Contains("<DIR>")); }); foreach (string item in rawList) { if (!string.IsNullOrEmpty(item)) { FtpFileInfo ftpFileInfo = new FtpFileInfo(); ftpFileInfo.Name = ".."; ftpFileInfo = ParseWindowsStyleFtpFile(item); ftpFileInfo.ParentDirectory = parentPath; if (ftpFileInfo != null && ftpFileInfo.Name != "." && ftpFileInfo.Name != ".." && !ftpFileInfo.IsDirectory) { result.Add(ftpFileInfo); } } } break; case FtpFileStyle.UnixStyle: rawList.RemoveAll(delegate(string item) { return(item.StartsWith("d", StringComparison.OrdinalIgnoreCase)); }); foreach (string item in rawList) { if (!string.IsNullOrEmpty(item)) { FtpFileInfo ftpFileInfo = new FtpFileInfo(); ftpFileInfo.Name = ".."; ftpFileInfo = ParseUnixStyleFtpFile(item); ftpFileInfo.ParentDirectory = parentPath; if (ftpFileInfo != null && ftpFileInfo.Name != "." && ftpFileInfo.Name != ".." && !ftpFileInfo.IsDirectory) { result.Add(ftpFileInfo); } } } break; case FtpFileStyle.Unknown: default: break; } return(result); }