static ServerFileData ParseUnixDirLine(string line) { ServerFileData sfd = new ServerFileData(); try { string[] parsed = new string[8]; int index = 0; int position; // Parse out the elements position = line.IndexOf(' '); while (index < parsed.Length) { parsed[index] = line.Substring(0, position); line = line.Substring(position); line = line.Trim(); index++; position = line.IndexOf(' '); } sfd.FileName = line; sfd.Permission = parsed[0]; sfd.Owner = parsed[2]; sfd.Group = parsed[3]; sfd.Size = Convert.ToInt32(parsed[4]); sfd.Date = parsed[5] + ' ' + parsed[6] + ' ' + parsed[7]; sfd.IsDirectory = sfd.Permission[0] == 'd'; } catch { sfd = null; } return sfd; }
static ServerFileData ParseUnixDirLine(string line) { ServerFileData sfd = new ServerFileData(); try { string[] parsed = new string[8]; int index = 0; int position; // Parse out the elements position = line.IndexOf(' '); while (index < parsed.Length) { parsed[index] = line.Substring(0, position); line = line.Substring(position); line = line.Trim(); index++; position = line.IndexOf(' '); } sfd.FileName = line; sfd.Permission = parsed[0]; sfd.Owner = parsed[2]; sfd.Group = parsed[3]; sfd.Size = Convert.ToInt32(parsed[4]); sfd.Date = parsed[5] + ' ' + parsed[6] + ' ' + parsed[7]; sfd.IsDirectory = sfd.Permission[0] == 'd'; } catch { sfd = null; } return(sfd); }
static ServerFileData ParseDosDirLine(string line) { ServerFileData sfd = new ServerFileData(); try { string[] parsed = new string[3]; int index = 0; int position = 0; // Parse out the elements position = line.IndexOf(' '); while (index < parsed.Length) { parsed[index] = line.Substring(0, position); line = line.Substring(position); line = line.Trim(); index++; position = line.IndexOf(' '); } sfd.FileName = line; if (parsed[2] != "<DIR>") sfd.Size = Convert.ToInt32(parsed[2]); sfd.Date = parsed[0] + ' ' + parsed[1]; sfd.IsDirectory = parsed[2] == "<DIR>"; } catch { sfd = null; } return sfd; }
/// <summary> /// Retorna una lista de ServerFileData parseada de una lista LSTI /// </summary> /// <param name="list"></param> /// <returns></returns> public List <ServerFileData> ParseLSTCommandResponse(String[] list) { List <ServerFileData> listServerFileData = new List <ServerFileData>(); ServerFileData d = null; foreach (string file in list) { if (!String.IsNullOrEmpty(file)) { d = Util.ParseUnixDirList(file); listServerFileData.Add(d); } } return(listServerFileData); }
/// <summary> /// Convierte una linea retornada atraves del comando FTP LIST a un objeto tipificado.- /// Ejemplo: linea proveniente de un server Unix /// -rwxrwxr-- 1 andrw video 3621773 Jan 31 2003 2FOR GOOD - You And Me.MP3 /// </summary> /// <param name="sDir"></param> internal static ServerFileData ParseUnixDirList(string fileLine) { try { fileLine = fileLine.Replace("\r", string.Empty); //string[] sFile = sDir.Split(new Char[] { '\r' }); ServerFileData sfd = null; int autodetect = 0; //foreach (string fileLine in sDir) //{ if (autodetect == 0) { sfd = ParseDosDirLine(fileLine); if (sfd == null) { sfd = ParseUnixDirLine(fileLine); autodetect = 2; } else { autodetect = 1; } } else if (autodetect == 1) { sfd = ParseDosDirLine(fileLine); } else if (autodetect == 2) { sfd = ParseUnixDirLine(fileLine); } //} return(sfd); } catch (Exception e) { throw e; } }
/// <summary> /// Convierte una linea retornada atraves del comando FTP LIST a un objeto tipificado.- /// Ejemplo: linea proveniente de un server Unix /// -rwxrwxr-- 1 andrw video 3621773 Jan 31 2003 2FOR GOOD - You And Me.MP3 /// </summary> /// <param name="fileLine">Es una linea que retorna de las que retorna el comando LIST</param> internal static ServerFileData ParseUnixDirList(string fileLine) { try { fileLine = fileLine.Replace("\r", string.Empty); ServerFileData sfd = null; int autodetect = 0; if (autodetect == 0) { sfd = ParseDosDirLine(fileLine); if (sfd == null) { sfd = ParseUnixDirLine(fileLine); autodetect = 2; } else { autodetect = 1; } } else if (autodetect == 1) { sfd = ParseDosDirLine(fileLine); } else if (autodetect == 2) { sfd = ParseUnixDirLine(fileLine); } return(sfd); } catch (Exception e) { throw e; } }
static ServerFileData ParseDosDirLine(string line) { ServerFileData sfd = new ServerFileData(); try { string[] parsed = new string[3]; int index = 0; int position = 0; // Parse out the elements position = line.IndexOf(' '); while (index < parsed.Length) { parsed[index] = line.Substring(0, position); line = line.Substring(position); line = line.Trim(); index++; position = line.IndexOf(' '); } sfd.FileName = line; if (parsed[2] != "<DIR>") { sfd.Size = Convert.ToInt32(parsed[2]); } sfd.Date = parsed[0] + ' ' + parsed[1]; sfd.IsDirectory = parsed[2] == "<DIR>"; } catch { sfd = null; } return(sfd); }
TreeNode GetNode(ServerFileData data) { TreeNode t = new TreeNode(data.FileName); t.Name = String.Concat(ftpComponent1.FTPPath, "/",data.FileName); if (data.IsDirectory) { t.Tag = "d"; t.ImageKey = "folder_close_16.png"; } if (!data.IsDirectory) { t.Tag = "f"; t.ImageKey = "doc_16.png"; t.SelectedImageKey = "doc_sel_16.ico"; } return t; }