/// <summary> /// Returns the LastWriteTime of the specified file/folder /// </summary> /// <param name="path">The common path to the file/folder</param> /// <returns></returns> public DateTime GetLwtOf(string path) { if (string.IsNullOrWhiteSpace(path)) { return(DateTime.MinValue); } if (path.StartsWith("/")) { path = path.Substring(1); } var dt = DateTime.MinValue; try { dt = (FTP) ? _ftpc.GetModifiedTime(path) : _sftpc.GetLastWriteTime(path); } catch (Exception ex) { Log.Write(l.Client, "===> {0} is a folder", path); Common.LogError(ex); } if (!FTP) { Log.Write(l.Client, "Got LWT: {0} UTC: {1}", dt, _sftpc.GetLastAccessTimeUtc(path)); } return(dt); }
/// <summary> /// Returns the LastWriteTime of the specified file/folder /// </summary> /// <param name="path">The common path to the file/folder</param> /// <returns></returns> public DateTime GetLwtOf(string path) { if (string.IsNullOrWhiteSpace(path)) { return(DateTime.MinValue); } if (path.StartsWith("/")) { path = path.Substring(1); } var cd = string.Empty; var dt = DateTime.MinValue; try { if (FTP && path != Common._name(path)) { var parent = path.Substring(0, path.Length - Common._name(path).Length); if (parent.PathHasSpace()) { // Fix for folders that contain spaces: The client will cd inside any // such folder and request a file/folder listing of the current directory cd = WorkingDirectory; _ftpc.ChangeDirectoryMultiPath(parent); path = Common._name(path); } } dt = (controller.Account.Protocol != FtpProtocol.SFTP) ? _ftpc.GetFileDateTime(path, true) : _sftpc.GetLastWriteTime(path); // If we changed directory, we should go back... if (FTP && cd != string.Empty) { while (WorkingDirectory != cd) { _ftpc.ChangeDirectoryMultiPath(".."); } } } catch (Exception ex) { Log.Write(l.Client, "===> {0} is a folder", path); Common.LogError(ex); } if (controller.Account.Protocol == FtpProtocol.SFTP) { Log.Write(l.Client, "Got LWT: {0} UTC: {1}", dt, _sftpc.GetLastAccessTimeUtc(path)); } return(dt); }
/// <summary> /// Returns the LastWriteTime of the specified file/folder /// </summary> /// <param name="path">The common path to the file/folder</param> /// <returns></returns> public override DateTime GetLwtOf(string path) { if (string.IsNullOrWhiteSpace(path)) { return(DateTime.MinValue); } if (path.StartsWith("/")) { path = path.Substring(1); } var dt = DateTime.MinValue; try { lock (ftpcLock) { dt = _sftpc.GetLastWriteTime(path); } } catch (Exception ex) { Log.Write(l.Client, "===> {0} is a folder", path); Common.LogError(ex); } DateTime tmp = DateTime.MinValue; lock (ftpcLock) { try { tmp = _sftpc.GetLastAccessTimeUtc(path); } catch (Exception ex) { Log.Write(l.Client, "===> some files/directory changed"); Common.LogError(ex); } } Log.Write(l.Client, "Got LWT: {0} UTC: {1}", dt, tmp); return(dt); }