/// <summary> /// Try to auto-detect which parser is suitable given a system string. /// </summary> public void Init(FtpOperatingSystem system, FtpParser defaultParser) { ParserConfirmed = false; if (system == FtpOperatingSystem.Windows) { CurrentParser = FtpParser.Windows; } else if (system == FtpOperatingSystem.Unix) { CurrentParser = FtpParser.Unix; } else if (system == FtpOperatingSystem.VMS) { CurrentParser = FtpParser.VMS; } else if (system == FtpOperatingSystem.IBMOS400) { CurrentParser = FtpParser.IBM; } else { CurrentParser = defaultParser; client.LogStatus(FtpTraceLevel.Warn, "Cannot auto-detect listing parser for system '" + system + "', using " + defaultParser + " parser"); } DetectedParser = CurrentParser; }
/// <summary> /// Try to auto-detect which parser is suitable given a system string. /// </summary> public void Init(FtpOperatingSystem system, FtpParser forcedParser = FtpParser.Auto) { ParserConfirmed = false; if (forcedParser != FtpParser.Auto) { // use the parser that the server handler specified CurrentParser = forcedParser; } else { if (system == FtpOperatingSystem.Windows) { CurrentParser = FtpParser.Windows; } else if (system == FtpOperatingSystem.Unix || system == FtpOperatingSystem.SunOS) { CurrentParser = FtpParser.Unix; } else if (system == FtpOperatingSystem.VMS) { CurrentParser = FtpParser.VMS; } else if (system == FtpOperatingSystem.IBMOS400 || system == FtpOperatingSystem.IBMzOS) { CurrentParser = FtpParser.IBM; } else { CurrentParser = FtpParser.Unix; client.LogStatus(FtpTraceLevel.Warn, "Cannot auto-detect listing parser for system '" + system + "', using Unix parser"); } } DetectedParser = CurrentParser; }
/// <summary> /// Converts the FTP date string into a DateTime object, without performing any timezone conversion. /// </summary> /// <param name="dateString">The date string</param> /// <param name="formats">Date formats to try parsing the value from (eg "yyyyMMddHHmmss")</param> /// <returns>A <see cref="DateTime"/> object representing the date, or <see cref="DateTime.MinValue"/> if there was a problem</returns> public static DateTime ParseFtpDate(this string dateString, FtpClient client, string[] formats = null) { if (formats == null) { formats = FtpDateFormats; } // parse the raw timestamp without performing any timezone conversions try { DateTime date = DateTime.ParseExact(dateString, FtpDateFormats, client.ListingCulture.DateTimeFormat, DateTimeStyles.None); // or client.ListingCulture.DateTimeFormat return(date); } catch (FormatException) { client.LogStatus(FtpTraceLevel.Error, "Failed to parse date string '" + dateString + "'"); } return(DateTime.MinValue); }
/// <summary> /// Get the full path of a given FTP Listing entry /// </summary> public static void CalculateFullFtpPath(this FtpListItem item, FtpClient client, string path, bool isVMS) { // EXIT IF NO DIR PATH PROVIDED if (path == null) { // check if the path is absolute if (IsAbsolutePath(item.Name)) { item.FullName = item.Name; item.Name = item.Name.GetFtpFileName(); } return; } // ONLY IF DIR PATH PROVIDED // if this is a vax/openvms file listing // there are no slashes in the path name if (isVMS) { item.FullName = path + item.Name; } else { //this.client.LogStatus(item.Name); // remove globbing/wildcard from path if (path.GetFtpFileName().Contains("*")) { path = path.GetFtpDirectoryName(); } if (item.Name != null) { // absolute path? then ignore the path input to this method. if (IsAbsolutePath(item.Name)) { item.FullName = item.Name; item.Name = item.Name.GetFtpFileName(); } else if (path != null) { item.FullName = path.GetFtpPath(item.Name); //.GetFtpPathWithoutGlob(); } else { client.LogStatus(FtpTraceLevel.Warn, "Couldn't determine the full path of this object: " + Environment.NewLine + item.ToString()); } } // if a link target is set and it doesn't include an absolute path // then try to resolve it. if (item.LinkTarget != null && !item.LinkTarget.StartsWith("/")) { if (item.LinkTarget.StartsWith("./")) { item.LinkTarget = path.GetFtpPath(item.LinkTarget.Remove(0, 2)).Trim(); } else { item.LinkTarget = path.GetFtpPath(item.LinkTarget).Trim(); } } } }