/// <summary> /// Constructor taking a directory listing line and path /// </summary> /// <param name="line">The line returned from the detailed directory list</param> /// <param name="path">Path of the directory</param> /// <remarks></remarks> public FTPfileInfo(string line, string path) { //parse line Match m = GetMatchingRegex(line); if (m == null) { //failed throw new ApplicationException("Unable to parse line: " + line); } else { _filename = m.Groups["name"].Value; _path = path; _size = Convert.ToInt64(m.Groups["size"].Value); _permission = m.Groups["permission"].Value; string _dir = m.Groups["dir"].Value; if ((!string.IsNullOrEmpty(_dir) & _dir != "-")) { _fileType = DirectoryEntryTypes.Directory; } else { _fileType = DirectoryEntryTypes.File; } try { _fileDateTime = System.DateTime.Parse(m.Groups["timestamp"].Value); } catch (Exception ex) { _fileDateTime = null; } } }
/// <summary> /// Constructor taking a directory listing line and path /// </summary> /// <param name="line">The line returned from the detailed directory list</param> /// <param name="path">Path of the directory</param> /// <remarks></remarks> public FTPfileInfo(string line, string path) { //parse line Match m = GetMatchingRegex(line); if (m == null) { throw (new ApplicationException("Unable to parse line: " + line)); } else { _filename = m.Groups["name"].Value; _path = path; Int64.TryParse(m.Groups["size"].Value, out _size); _permission = m.Groups["permission"].Value; string _dir = m.Groups["dir"].Value; if (_dir != "" && _dir != "-") { _fileType = DirectoryEntryTypes.Directory; } else { _fileType = DirectoryEntryTypes.File; } try { _fileDateTime = DateTime.Parse(m.Groups["timestamp"].Value); } catch (Exception) { _fileDateTime = Convert.ToDateTime(null); } } }
public FTPfileInfo(string line, string path) { Match matchingRegex = this.GetMatchingRegex(line); if (matchingRegex == null) { throw new ApplicationException("Unable to parse line: " + line); } this._filename = matchingRegex.Groups["name"].Value; this._path = path; long.TryParse(matchingRegex.Groups["size"].Value, out this._size); this._permission = matchingRegex.Groups["permission"].Value; string str = matchingRegex.Groups["dir"].Value; if ((str != "") && (str != "-")) { this._fileType = DirectoryEntryTypes.Directory; } else { this._fileType = DirectoryEntryTypes.File; } try { this._fileDateTime = DateTime.Parse(matchingRegex.Groups["timestamp"].Value); } catch (Exception) { this._fileDateTime = Convert.ToDateTime((string) null); } }
/// <summary> /// 构造方法 /// </summary> /// <param name="diaplayName"></param> /// <param name="fileInfoType"></param> /// <param name="fileSize"></param> /// <param name="lastEditTime"></param> public FileDirectoryInfo(string displayName, DirectoryEntryTypes fileInfoType, long fileSize, DateTime lastEditTime) { this.displayName = displayName; this.fileSize = fileSize; this.fileInfoType = fileInfoType; this.lastEditTime = lastEditTime; }
/// <summary> /// Constructor taking a directory listing line and path /// </summary> /// <param name="line">The line returned from the detailed directory list</param> /// <param name="path">Path of the directory</param> /// <remarks></remarks> public FTPfileInfo(string line, string path, string hostName) { //parse line Match m = GetMatchingRegex(line); if (m == null) { //failed throw (new ApplicationException("Unable to parse line: " + line)); } else { _filename = m.Groups["name"].Value; _path = path; Int64.TryParse(m.Groups["size"].Value, out _size); //_size = System.Convert.ToInt32(m.Groups["size"].Value); _permission = m.Groups["permission"].Value; string _dir = m.Groups["dir"].Value; if (_dir != "" && _dir != "-") { _fileType = DirectoryEntryTypes.Directory; } else { _fileType = DirectoryEntryTypes.File; } try { // 第一种方法不准,因为response string本来就有点问题。详情可调之。 //_fileDateTime = DateTime.Parse(m.Groups["timestamp"].Value); // 改用 "MDTM" 命令。 _fileDateTime = GetFtpFileTime(_filename, _path, hostName); } catch (Exception) { _fileDateTime = Convert.ToDateTime(null); } } }
/// <summary> /// 解析FTPstrPath下所有文件 /// </summary> /// <param name="strLine"></param> /// <param name="strPath"></param> public FTPFile(string strLine, string strPath) { Match m = GetMatchingRegex(strLine); if (m == null) { throw (new ApplicationException("Unable to parse line: " + strLine)); } else { m_strFileName = m.Groups["name"].Value; m_strPath = strPath; Int64.TryParse(m.Groups["size"].Value, out m_nSize); m_strPermission = m.Groups["permission"].Value; string _dir = m.Groups["dir"].Value; if (_dir != "" && _dir != "-") { m_nFileType = DirectoryEntryTypes.Directory; } else { m_nFileType = DirectoryEntryTypes.File; } try { String strValue = m.Groups["timestamp"].Value; m_FileDateTime = DateTime.Parse(strValue); } catch (Exception) { m_FileDateTime = Convert.ToDateTime(null); } } }
/// <summary> /// Constructor taking a directory listing line and path /// </summary> /// <param name="line">The line returned from the detailed directory list</param> /// <param name="path">Path of the directory</param> /// <remarks></remarks> public FTPfileInfo(string line, string path) { //parse line Match m = GetMatchingRegex(line); if (m == null) { //failed throw (new ApplicationException("Unable to parse line: " + line)); } else { _filename = m.Groups["name"].Value; _path = path; Int64.TryParse(m.Groups["size"].Value, out _size); //_size = System.Convert.ToInt32(m.Groups["size"].Value); _permission = m.Groups["permission"].Value; string _dir = m.Groups["dir"].Value; if (_dir != "" && _dir != "-") { _fileType = DirectoryEntryTypes.Directory; } else { _fileType = DirectoryEntryTypes.File; } try { _fileDateTime = DateTime.Parse(m.Groups["timestamp"].Value); } catch (Exception) { _fileDateTime = Convert.ToDateTime(null); } } }
/// <summary> /// Constructor taking a directory listing line and path /// </summary> /// <param name="line">The line returned from the detailed directory list</param> /// <param name="path">Path of the directory</param> /// <param name="isUnix">If the ftp server runs on Unix, the datetime format will be different. </param> /// <remarks></remarks> public FTPfileInfo(string line, string path, bool isUnix) { //parse line Match m = GetMatchingRegex(line); //log // //Logger.Error(string.Format("Parse Line: {0}",line)); if (m == null) { //failed if (!line.StartsWith("total")) { throw (new ApplicationException("Unable to parse line: " + line)); } } else { _filename = m.Groups["name"].Value; _path = path; Int64.TryParse(m.Groups["size"].Value, out _size); //_size = System.Convert.ToInt32(m.Groups["size"].Value); _permission = m.Groups["permission"].Value; string _dir = m.Groups["dir"].Value; if (_dir != "" && _dir != "-") { _fileType = DirectoryEntryTypes.Directory; } else { _fileType = DirectoryEntryTypes.File; } try { if (isUnix) { if (m.Groups["timestamp"].Value.ToCharArray()[4] == ' ') { _fileDateTime = DateTime.ParseExact(m.Groups["timestamp"].Value, "MMM d HH:mm", culture, System.Globalization.DateTimeStyles.NoCurrentDateDefault); } else { _fileDateTime = DateTime.ParseExact(m.Groups["timestamp"].Value, "MMM d HH:mm", culture, System.Globalization.DateTimeStyles.NoCurrentDateDefault); } } else { // Regex reg=new Regex(@"[0-9]{2}-[0-9]{2}-[0-9]{2}\s{2}") _fileDateTime = DateTime.Parse(m.Groups["timestamp"].Value); } } catch (Exception) { _fileDateTime = Convert.ToDateTime(null); } } }