繁体   English   中英

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

[英]C# FTP Response.LastModified always returns 1/1/0001 12:00:00 AM

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

我有同样的问题。 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);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM