/// <summary> /// Gets the modified time of a remote file asynchronously /// </summary> /// <param name="path">The full path to the file</param> /// <param name="type">Return the date in local timezone or UTC? Use FtpDate.Original to disable timezone conversion.</param> /// <param name="token">The token that can be used to cancel the entire process</param> /// <returns>The modified time, or <see cref="DateTime.MinValue"/> if there was a problem</returns> public async Task <DateTime> GetModifiedTimeAsync(string path, FtpDate type = FtpDate.Original, CancellationToken token = default(CancellationToken)) { // verify args if (path.IsBlank()) { throw new ArgumentException("Required parameter is null or blank.", "path"); } LogFunc(nameof(GetModifiedTimeAsync), new object[] { path, type }); var date = DateTime.MinValue; FtpReply reply; // get modified date of a file if ((reply = await ExecuteAsync("MDTM " + path.GetFtpPath(), token)).Success) { date = reply.Message.GetFtpDate(TimeConversion); // convert server timezone to UTC, based on the TimeOffset property if (type != FtpDate.Original && m_listParser.HasTimeOffset) { date = date - m_listParser.TimeOffset; } // convert to local time if wanted #if !CORE if (type == FtpDate.Local) { date = TimeZone.CurrentTimeZone.ToLocalTime(date); } #endif } return(date); }
/// <summary> /// Begins an asynchronous operation to get the modified time of a remote file /// </summary> /// <param name="path">The full path to the file</param> /// <param name="date">The new modified date/time value</param> /// <param name="type">Is the date provided in local timezone or UTC? Use FtpDate.Original to disable timezone conversion.</param> /// <param name="callback">Async callback</param> /// <param name="state">State object</param> /// <returns>IAsyncResult</returns> public IAsyncResult BeginSetModifiedTime(string path, DateTime date, FtpDate type, AsyncCallback callback, object state) { IAsyncResult ar; AsyncSetModifiedTime func; lock (m_asyncmethods) { ar = (func = SetModifiedTime).BeginInvoke(path, date, type, callback, state); m_asyncmethods.Add(ar, func); } return(ar); }
/// <summary> /// Changes the modified time of a remote file /// </summary> /// <param name="path">The full path to the file</param> /// <param name="date">The new modified date/time value</param> /// <param name="type">Is the date provided in local timezone or UTC? Use FtpDate.Original to disable timezone conversion.</param> public virtual void SetModifiedTime(string path, DateTime date, FtpDate type = FtpDate.Original) { // verify args if (path.IsBlank()) { throw new ArgumentException("Required parameter is null or blank.", "path"); } if (date == null) { throw new ArgumentException("Required parameter is null or blank.", "date"); } LogFunc(nameof(SetModifiedTime), new object[] { path, date, type }); FtpReply reply; #if !CORE14 lock (m_lock) { #endif // convert local to UTC if wanted #if !CORE if (type == FtpDate.Local) { date = TimeZone.CurrentTimeZone.ToUniversalTime(date); } #endif // convert UTC to server timezone, based on the TimeOffset property if (type != FtpDate.Original && m_listParser.HasTimeOffset) { date = date + m_listParser.TimeOffset; } // set modified date of a file var timeStr = date.ToString("yyyyMMddHHmmss"); if ((reply = Execute("MFMT " + timeStr + " " + path.GetFtpPath())).Success) { } #if !CORE14 } #endif }