Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving creation date of file (FTP)

I'm using the System.Net.FtpWebRequest class and my code is as follows:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://example.com/folder");
request.Method = WebRequestMethods.Ftp.ListDirectory;

request.Credentials = new NetworkCredential("username", "password");

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

string names = reader.ReadToEnd();

reader.Close();
response.Close();

This is based off of the examples provided on MSDN but I couldn't find anything more detailed.

I'm storing all the filenames in the folder in names but how can I now iterate through each of those and retrieve their dates? I want to retrieve the dates so I can find the newest files. Thanks.

like image 773
Radu Avatar asked Dec 15 '10 19:12

Radu


People also ask

How do you check when was a file created?

You can show the "creation date" that is stored for files in the Windows Explorer easily: Switch Windows Explorer to column view, right click a column header and and in the context menu that pops up select "Creation Date" for enabling the additional column. Note that this setting is folder-specific.

Does FTP preserve timestamp?

Caveat: Most FTP clients support the ability to send a file's original modified timestamp during a transfer, however, most DO NOT support the ability to send both the original modified AND created date/time during a transfer. Please consult with your FTP client's support team to confirm the available capabilities.

When was the FTP server developed?

FTP was first designed back in 1971, before TCP and IP even existed. The current specification was created in 1985.

What is archive in FTP?

People soon realized that FTP was also a very good method for giving others access to public files without requiring private system accounts. The files, called an FTP archive, can be accessed by anyone who logs into a general public account named "anonymous" with the password "ftp".


1 Answers

This seems to work just fine http://msdn.microsoft.com/en-us/library/system.net.ftpwebresponse.lastmodified(v=VS.90).aspx

FtpWebRequest request = (FtpWebRequest)WebRequest.Create (serverUri);
request.Method = WebRequestMethods.Ftp.GetDateTimestamp;
FtpWebResponse response = (FtpWebResponse)request.GetResponse ();
Console.WriteLine ("{0} {1}",serverUri,response.LastModified);
like image 86
Jack0fshad0ws Avatar answered Sep 30 '22 01:09

Jack0fshad0ws