/* * /// <summary> * /// Initializes a new FtpListItem object from a parser's results. * /// </summary> * /// <param name="parser"> </param> * private FtpListItem(FtpListFormatParser parser) * : this() * { * this.Type = parser.ObjectType; * this.Name = parser.Name; * this.Size = parser.Size; * this.Modify = parser.Modify; * this.Mode = parser.Mode; * this.Owner = parser.Owner; * this.Group = parser.Group; * } */ /// <summary>Parses a given listing</summary> /// <param name="listing"> The single line that needs to be parsed </param> /// <param name="type"> The command that generated the line to be parsed </param> private FtpListItem(string listing, FtpListType type) : this() { this.Parse(listing, type); }
/* /// <summary> /// Initializes a new FtpListItem object from a parser's results. /// </summary> /// <param name="parser"> </param> private FtpListItem(FtpListFormatParser parser) : this() { this.Type = parser.ObjectType; this.Name = parser.Name; this.Size = parser.Size; this.Modify = parser.Modify; this.Mode = parser.Mode; this.Owner = parser.Owner; this.Group = parser.Group; } */ /// <summary>Parses a given listing</summary> /// <param name="listing"> The single line that needs to be parsed </param> /// <param name="type"> The command that generated the line to be parsed </param> private FtpListItem(string listing, FtpListType type) : this() { this.Parse(listing, type); }
/// <summary> /// Parses a given listing /// </summary> /// <param name="listing"></param> /// <param name="type"></param> public FtpListItem(string[] listing, FtpListType type) : this() { foreach (string s in listing) { this.Parse(s, type); } }
/// <summary>Parses an array of list results</summary> /// <param name="sequence"> Array of list results </param> /// <param name="ftpListType"> The command that generated the list being parsed </param> /// <returns> </returns> public static IEnumerable <FtpListItem> ParseList(IEnumerable <string> sequence, FtpListType ftpListType) { return(from item in sequence let ftpListItem = new FtpListItem(item, ftpListType) where ftpListItem.Type != FtpObjectType.Unknown select ftpListItem); }
/// <summary> /// Parses an array of list results /// </summary> /// <param name="items">Array of list results</param> /// <param name="type">The command that generated the list being parsed</param> /// <returns></returns> public static FtpListItem[] ParseList(string[] items, FtpListType type) { List <FtpListItem> lst = new List <FtpListItem>(); foreach (string s in items) { FtpListItem i = new FtpListItem(s, type); if (i.Type != FtpObjectType.Unknown) { lst.Add(i); } } return(lst.ToArray()); }
/// <summary> /// Parses a given listing /// </summary> /// <param name="listing">The single line that needs to be parsed</param> /// <param name="type">The command that generated the line to be parsed</param> public bool Parse(string listing, FtpListType type) { if (type == FtpListType.MLSD || type == FtpListType.MLST) { this.ParseMachineListing(listing); } else if (type == FtpListType.LIST) { this.ParseListListing(listing); } else { throw new NotImplementedException(string.Format("{0} style formats are not supported.", type.ToString())); } return(this.Type != FtpObjectType.Unknown); }
/// <summary> /// Retrieve a list of files, directories, or both files and directories from remote server /// </summary> /// <param name="directoryPath"></param> /// <param name="listType"></param> /// <returns></returns> public FileStruct[] List(string directoryPath, FtpListType listType) { Console.WriteLine("Fetching: {0}", directoryPath); switch (listType) { case FtpListType.Directories: return(FtpListParser.DirectoryList(ListDirectoryDetails(directoryPath))); case FtpListType.Files: return(FtpListParser.FileList(ListDirectoryDetails(directoryPath))); case FtpListType.Full: return(FtpListParser.FullListing(ListDirectoryDetails(directoryPath))); default: throw new Exception("FtpListType not found for:" + listType); } }
/// <summary>Parses a given listing</summary> /// <param name="listing"> The single line that needs to be parsed </param> /// <param name="type"> The command that generated the line to be parsed </param> private bool Parse(string listing, FtpListType type) { if (type == FtpListType.MLSD || type == FtpListType.MLST) { this.ParseMachineListing(listing); } else if (type == FtpListType.LIST) { this.ParseListListing(listing); } else { var message = string.Format("{0} style formats are not supported.", type); throw new NotImplementedException(message); } var success = this.Type != FtpObjectType.Unknown; return(success); }
/// <summary> /// Gets a file listing, parses it, and returns an array of FtpListItem /// objects that contain the parsed information. Supports MLSD/LIST (DOS and UNIX) formats. /// Most people should use the FtpDirectory/FtpFile classes which have more features than /// the objects returned from this method. /// </summary> /// <param name="path"></param> /// <param name="type"></param> /// <returns></returns> public FtpListItem[] GetListing(string path, FtpListType type) { FtpListItem[] list = FtpListItem.ParseList(this.GetRawListing(path, type), type); // parsing last write time out of most LIST formats is not feasible so it's ignored. // if the server supports the MDTM command and pipelining is enable, we // can go ahead and retrieve the last write time's of the files in this list. if (list.Length > 0 && this.EnablePipelining && this.HasCapability(FtpCapability.MDTM)) { List<FtpListItem> items = new List<FtpListItem>(); for (int i = 0; i < list.Length; i++) { if (list[i].Type == FtpObjectType.File && list[i].Modify == DateTime.MinValue) { items.Add(list[i]); } } if (items.Count > 0) { this.BeginExecute(); foreach (FtpListItem i in items) { this.Execute("MDTM {0}/{1}", path, i.Name); } FtpCommandResult[] res = this.EndExecute(); for (int i = 0; i < res.Length; i++) { if (res[i].ResponseStatus) { items[i].Modify = this.ParseLastWriteTime(res[i].ResponseMessage); } } } } return list; }
/// <summary> /// Returns a raw file listing using the specified LIST type /// </summary> /// <param name="path">The full or relative (to the current working directory) path</param> /// <param name="type"></param> /// <returns>string array of the raw listing</returns> public string[] GetRawListing(string path, FtpListType type) { List<string> lst = new List<string>(); string cmd, buf; switch (type) { case FtpListType.LIST: cmd = "LIST"; break; case FtpListType.MLSD: case FtpListType.MLST: cmd = "MLSD"; break; default: throw new NotImplementedException("The specified list type has not been implemented."); } using (FtpDataStream s = this.OpenDataStream(FtpDataType.ASCII)) { if (!s.Execute("{0} {1}", cmd, path)) { throw new FtpCommandException(this); } while ((buf = s.ReadLine()) != null) { lst.Add(buf); } } return lst.ToArray(); }
/// <summary>Parses a given listing</summary> /// <param name="listing"> The single line that needs to be parsed </param> /// <param name="type"> The command that generated the line to be parsed </param> private bool Parse(string listing, FtpListType type) { if (type == FtpListType.MLSD || type == FtpListType.MLST) { this.ParseMachineListing(listing); } else if (type == FtpListType.LIST) { this.ParseListListing(listing); } else { var message = string.Format("{0} style formats are not supported.", type); throw new NotImplementedException(message); } var success = this.Type != FtpObjectType.Unknown; return success; }
/// <summary>Parses an array of list results</summary> /// <param name="sequence"> Array of list results </param> /// <param name="ftpListType"> The command that generated the list being parsed </param> /// <returns> </returns> public static IEnumerable<FtpListItem> ParseList(IEnumerable<string> sequence, FtpListType ftpListType) { return from item in sequence let ftpListItem = new FtpListItem(item, ftpListType) where ftpListItem.Type != FtpObjectType.Unknown select ftpListItem; }
/// <summary> /// Parses an array of list results /// </summary> /// <param name="items">Array of list results</param> /// <param name="type">The command that generated the list being parsed</param> /// <returns></returns> public static FtpListItem[] ParseList(string[] items, FtpListType type) { List<FtpListItem> lst = new List<FtpListItem>(); foreach (string s in items) { FtpListItem i = new FtpListItem(s, type); if (i.Type != FtpObjectType.Unknown) { lst.Add(i); } } return lst.ToArray(); }
/// <summary> /// Parses a given listing /// </summary> /// <param name="listing"></param> /// <param name="type"></param> public FtpListItem(string[] listing, FtpListType type) : this() { foreach (string s in listing) { this.Parse(s, type); } }
/// <summary> /// Parses a given listing /// </summary> /// <param name="listing">The single line that needs to be parsed</param> /// <param name="type">The command that generated the line to be parsed</param> public bool Parse(string listing, FtpListType type) { if (type == FtpListType.MLSD || type == FtpListType.MLST) { this.ParseMachineListing(listing); } else if (type == FtpListType.LIST) { this.ParseListListing(listing); } else { throw new NotImplementedException(string.Format("{0} style formats are not supported.", type.ToString())); } return this.Type != FtpObjectType.Unknown; }