private FtpFileInfo[] ParseIIS(string[] lines, int startFrom) { FtpFileInfo[] result = new FtpFileInfo[lines.Length - startFrom]; for (int i = startFrom; i < lines.Length; i++) { var match = _iisFileLine.Match(lines[i]); if (!match.Success) throw new Exception("Cannot parse file info. First line was ok."); int year = int.Parse(match.Groups["year"].Value); if (year < 100) if (year > 50) year = 1900 + year; else year = 2000 + year; int month = int.Parse(match.Groups["month"].Value); int day = int.Parse(match.Groups["day"].Value); int hour = int.Parse(match.Groups["hour"].Value); int minute = int.Parse(match.Groups["minute"].Value); bool am = match.Groups["ampm"].Value == "AM"; string lengthStr = match.Groups["length"].Value; bool directory = lengthStr == "<DIR>"; long length = 0; if (!directory) length = long.Parse(lengthStr); string name = match.Groups["name"].Value; result[i - startFrom] = new FtpFileInfo { ModifiedDate = new DateTime(year, month, day, hour, minute, 0), Length = length, Name = name, IsDirectory = directory }; } return result; }
private FtpFileInfo[] ParseUnix(string[] lines, int startFrom) { FtpFileInfo[] result = new FtpFileInfo[lines.Length - startFrom]; for (int i = startFrom; i < lines.Length; i++) { var match = _unixFileLine.Match(lines[i]); // skip links for now if (lines[i].Length > 0 && lines[i][0] == 'l') continue; if (!match.Success) throw new Exception("Cannot parse file info. First line was ok."); string yearStr = match.Groups["year"].Value; int year = yearStr == "" ? DateTime.Now.Year : int.Parse(yearStr); int month = Parse3CharMonth(match.Groups["month"].Value); int day = int.Parse(match.Groups["day"].Value); string hourStr = match.Groups["hour"].Value; int hour = hourStr == "" ? 0 : int.Parse(hourStr); string minuteStr = match.Groups["minute"].Value; int minute = minuteStr == "" ? 0 : int.Parse(minuteStr); long length = long.Parse(match.Groups["length"].Value); string name = match.Groups["name"].Value; bool directory = match.Groups["dir"].Value == "d"; if (directory) length = 0; if (directory && (name == "." || name == "..")) continue; result[i - startFrom] = new FtpFileInfo { ModifiedDate = new DateTime(year, month, day, hour, minute, 0), Length = length, Name = name, IsDirectory = directory }; } return result.Where(r => r != null).ToArray(); }