Question

I'm trying to get the date and time from some files in my ftp but it always returns 1/1/0001 12:00:00 AM .. Why?

Everything seems to be working fine, what am I doing wrong?

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();
 }
Was it helpful?

Solution

I had the same problem. file.Modified would always return "1/1/0001 12:00:00 AM" If you add the filter after the path, FtpListOption.Modify file.Modified will return the actual time now... blew my mind. I just figured this out a minute ago and using it in my application now.

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);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top