Modify Date in Ftp

Sep 21, 2011 at 12:23 AM

Hi

I am wondering what is the Modify referring too? Is it like if I would go and rename a file on my ftp site that would be considered modify? If so will you be adding in Creation Time as well(if that is possible)

 

Thanks.

Coordinator
Sep 21, 2011 at 12:35 AM

Modify is the last write (modification) time of the file. The modify time would have to be updated by the server in any case and I supposed it depends on the file system in regards to mtime being updated when a file is renamed. On windows with NTFS, renaming a file does not affect the last write time (modify).

Some servers do in fact give the creation time in MLS* listings if  I recall correctly however this doesn't seem to be common. An extension to the RFC added the MDTM command (modify) but there are no commands for other file times as far as I know. Modify is the only file time I intend to support unless there is abundant support on the server side for other file times in the MLS* listings. In most cases I believe the creation time is irrelevant. To some folks it may be a matter of concern and adding support for it to the MLS* parser in FtpListItem() should be easy enough if needed.

FYI, FtpListItem is a very generic structure for representing the files. Its main purpose in this project is simply parsing LIST and MLS* output. There are more classes, FtpDirectory and FtpFile which have more features including the ability to load information that wasn't provided by FtpListItem. They are the recommended way (by me) to work remote file system objects. You can access them through FtpClient.CurrentDirectory or creating your own instances of the classes.

Sep 21, 2011 at 8:46 PM
jptrosclair wrote:

Modify is the last write (modification) time of the file. The modify time would have to be updated by the server in any case and I supposed it depends on the file system in regards to mtime being updated when a file is renamed. On windows with NTFS, renaming a file does not affect the last write time (modify).

Some servers do in fact give the creation time in MLS* listings if  I recall correctly however this doesn't seem to be common. An extension to the RFC added the MDTM command (modify) but there are no commands for other file times as far as I know. Modify is the only file time I intend to support unless there is abundant support on the server side for other file times in the MLS* listings. In most cases I believe the creation time is irrelevant. To some folks it may be a matter of concern and adding support for it to the MLS* parser in FtpListItem() should be easy enough if needed.

FYI, FtpListItem is a very generic structure for representing the files. Its main purpose in this project is simply parsing LIST and MLS* output. There are more classes, FtpDirectory and FtpFile which have more features including the ability to load information that wasn't provided by FtpListItem. They are the recommended way (by me) to work remote file system objects. You can access them through FtpClient.CurrentDirectory or creating your own instances of the classes.

What would cause "modify" not being set? I mine don't seem to be set I get the default value of a "datetime" data type.

 

I will check those out but I only actually need the 3 properties it has. So I probably stick with using it. What is MLS*?

Coordinator
Sep 21, 2011 at 8:57 PM

FtpListItem's modify is set to DateTime.MinValue by default. If it isn't changed it means that either the last write time was not available in the listing that was parsed or, in some cases, the last write time is that is provided by the listing is ignored because it is not as accurate as what can be retrieved with MDTM. This is why you should use FtpDirectory and FtpFile. They automatically handle this situation. If the LastWriteTime isn't set in FtpDirectory or FtpFile it's automatically retrieved from the server using MDTM. If the LastWriteTIme is still DateTime.MinValue after that, then it's because the server doesn't support MDTM. FtpClient has a method for retrieving the last write time, you could also add a check in your code:

DateTime lastWrite = listing.Modify;

if(lastWrite == DateTime.MinValue && client.HasCapability(FtpCapability.MDTM)) {
   lastWrite = client.GetLastWriteTime(filePath);
}

MLS* is MLST and MLSD. The are extensions to the protocol that provided machine parse-able listings. This format is much better than what is given by LIST however machine listings aren't supported by all servers. The library prefers MLST and MLSD when they are available and if they're not then it just falls back to LIST. Unless you are telling it to use a specific format, you don't need to worry about this because the best choice is automatically used when available.

Sep 21, 2011 at 9:08 PM
Edited Sep 21, 2011 at 9:10 PM
jptrosclair wrote:

FtpListItem's modify is set to DateTime.MinValue by default. If it isn't changed it means that either the last write time was not available in the listing that was parsed or, in some cases, the last write time is that is provided by the listing is ignored because it is not as accurate as what can be retrieved with MDTM. This is why you should use FtpDirectory and FtpFile. They automatically handle this situation. If the LastWriteTime isn't set in FtpDirectory or FtpFile it's automatically retrieved from the server using MDTM. If the LastWriteTIme is still DateTime.MinValue after that, then it's because the server doesn't support MDTM. FtpClient has a method for retrieving the last write time, you could also add a check in your code:

 

DateTime lastWrite = listing.Modify;

if(lastWrite == DateTime.MinValue && client.HasCapability(FtpCapability.MDTM)) {
   lastWrite = client.GetLastWriteTime(filePath);
}

 

MLS* is MLST and MLSD. The are extensions to the protocol that provided machine parse-able listings. This format is much better than what is given by LIST however machine listings aren't supported by all servers. The library prefers MLST and MLSD when they are available and if they're not then it just falls back to LIST. Unless you are telling it to use a specific format, you don't need to worry about this because the best choice is automatically used when available.

Is this how I use it

 

      FtpDirectory a = new FtpDirectory(targetServerFtpCleint,targetServerFolderPath);
                var files = a.Files._list;
                var firstFile = files[0].Length;

Also what is timezone is the lastWriteTime? Is it UTC? And .Length would be equivalent to size? In List?
Coordinator
Sep 21, 2011 at 9:16 PM

The results of MDTM (FtpClient.GetLastWriteTime()) should be UTC, but it depends on the server. The results of the MLS* commands should also be UTC if I recall correctly. The MDTM command is used in almost all cases. The only case where it's not used internally is when the MLS* commands are supported because they provide accurate modification times already.