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.
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.
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.
FTP was first designed back in 1971, before TCP and IP even existed. The current specification was created in 1985.
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".
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With