Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Net.FtpWebRequest GetDateTimestamp example

I'm looking for a short bit of sample code which uses the System.Net.FtpWebRequest namespace to get the timestamp of a specified remote file on an ftp server. I know I need to set the Method property of my request object to WebRequestMethods.Ftp.GetDateTimestamp but I'm not sure how to get the response back into a System.DateTime object.

like image 472
Dav Evans Avatar asked Jun 24 '09 19:06

Dav Evans


1 Answers

Yep - thats pretty much what I ended up with. I went with something like this

request = FtpWebRequest.Create("ftp://ftp.whatever.com/somefile.txt");

request.Method = WebRequestMethods.Ftp.GetDateTimestamp;
request.Proxy = null;

using (FtpWebResponse resp = (FtpWebResponse)request.GetResponse())
{
        Console.WriteLine(resp.LastModified);
}
like image 125
Dav Evans Avatar answered Oct 09 '22 18:10

Dav Evans