C#FTP Response.LastModified始终返回1/1/0001 12:00:00 AM

时间:2013-09-11 13:34:00

标签: c# ftp response ftpwebrequest last-modified

我正试图从我的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();
 }

1 个答案:

答案 0 :(得分: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);
    }
}