【问题标题】:C# FTP Response.LastModified always returns 1/1/0001 12:00:00 AMC# FTP Response.LastModified 总是返回 1/1/0001 12:00:00 AM
【发布时间】:2013-09-11 13:33:59
【问题描述】:

我试图从我的 ftp 中的某些文件中获取日期和时间,但它总是返回 1/1/0001 12:00:00 AM .. 为什么?

一切似乎都很好,我做错了什么?

for (int i = 0; i < lsnames.Count; i++)
 {
     ftpclient = (FtpWebRequest)WebRequest.Create(FTPPATH + lsnames[i].ToString());
     ftpclient.Credentials = new NetworkCredential("username", "password");
     ftpclient.UsePassive = true;
     ftpclient.UseBinary = true;
     ftpclient.KeepAlive = false;
     ftpclient.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
     FtpWebResponse TimestampResponse = (FtpWebResponse)ftpclient.GetResponse();
     try { label2.Text = TimestampResponse.LastModified.ToString(); }
     catch { Label2Invocation(TimestampResponse.LastModified.ToString()); }
     Console.WriteLine("{0}", TimestampResponse.LastModified);
     MessageBox.Show("Dates: " + Convert.ToString(TimestampResponse.LastModified));
     TimestampResponse.Close();
 }

【问题讨论】:

    标签: c# ftp response ftpwebrequest last-modified


    【解决方案1】:

    我遇到了同样的问题。 file.Modified 将始终返回“1/1/0001 12:00:00 AM” 如果您在路径后添加过滤器,FtpListOption.Modify file.Modified 现在将返回实际时间......让我大吃一惊。我在一分钟前才发现这一点,现在在我的应用程序中使用它。

    foreach (var file in ftpClient.GetListing(newpath, FtpListOption.Modify))
    {
        //Console.WriteLine(file.Modified);
    
        if (file.Modified > lastRunTime)
        {
            //Download the file if it is newer than the last recorded run time.
            //WriteLine is for debugging purposes
            Console.WriteLine(file.Name);
        }
    }
    

    【讨论】:

    • 因为我刚才问了这个问题,所以我无法测试你的答案。虽然我怀疑这是正确的答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多