File modification date and time in FTP

  |   Jan.Sotola
FTP

Updated 16th Jul 2013: added description for IIS 8.0.

FTP protocol provides several ways to obtain a file's last modified date/time. The returned values may vary in time zone or time precision. This article discusses the technological background, describes a behavior of several common FTP servers and discusses what it means for Rebex FTP/SSL component.

What the FTP protocol provides

Last modification date/time of a file is retrieved in these two scenarios:

  1. As part of a directory listing. E.g. using Rebex FTP/SSL's
    GetList or GetItems methods.
    In FTP protocol, this corresponds to the following commands:

  2. MLSD – machine-readable directory listing, with entries that conform to a standardized format (RFC 3659). Rebex FTP/SSL uses this by default for servers that support it (modern FTP servers usually do).

  3. LIST – human-readable directory listing. This format is undefined, differs from server to server and is hard to parse. Rebex FTP/SSL includes parsers for the majority of commonly used formats.

  4. An explicit request for aninformation about a specific file.
    E.g.  using Rebex FTP/SSL's GetFileDateTime method. In FTP protocol, this corresponds to the following commands

  5. MLST – machine-readable individual file or directory information (conforms to RFC 3659). Rebex FTP/SSL uses this by default for servers that support it (modern FTP servers usually do).

  6. MDTM – a command that only retrieves file modification date/time and returns it in an easily-parsable format. Rebex FTP/SSL uses this for servers that don't support MLST. MDTM is defined by RFC 3659 as well, but lot of implementations predate the standard and use server's time zone instead of the proper UTC (GMT) in their response. Some older servers don't support neither MLST nor MDTM.

To find out whether the FTP server you are connected to supports MLSD or MLST command, examine the Rebex.Net.Ftp object's SupportedExtensions property:

if ((client.SupportedExtensions & FtpExtensions.MachineProcessingList) != 0)
    Console.WriteLine(“MLSD/MLST is supported.”);

To instruct Rebex FTP component to use the MDTM or LIST command even for servers that support MLST and MLSD, use the following code:

// disable MLSD (force LIST)
client.EnabledExtensions &= ~FtpExtensions.MachineProcessingList;

// enable MLSD if supported (default setting)
client.EnabledExtensions |= FtpExtensions.MachineProcessingList;

// disable MLST (force MDTM)
client.Settings.ForceMdtmForGetFileDateTime = true;

// enable MLST if supported (default setting)
client.Settings.ForceMdtmForGetFileDateTime = false;

Support by various FTP servers

The table below lists several common FTP servers and commands they support. The time zone used for each command is shown.

Server MDTM LIST** MLST/MLSD
FileZilla 0.9.32b UTC UTC UTC*
Gene6 FTP Server 3.10.0.2 UTC UTC UTC*
GlobalSCAPE EFT Server (v. 6.0) Local Local -
Microsoft FTP Service 8.0 (as well as 6.x and 7.x) UTC Local -
Ocean FTP Server 1.1.7 Local Local -
Titan FTP Server 6.25.623 UTC Local UTC*
VanDyke Software VShell FTPS Server 3.5.3 - Local UTC*
WS_FTP Server 5.0.4 UTC UTC UTC*
WU-FTPD 2.8.0 UTC UTC -
zFTP 3.0 UTC UTC UTC*
Notes:

The “Local” time for MDTM/LIST commands corresponds to the time zone of the server (not the client).

* The UTC time returned by MLST/MLSD is converted to local time by the Rebex FTP component, which means the returned time uses the client's time zone. To convert it back to UTC, use DateTime's .ToUniversalTime() method (which doesn't affect values returned by MDTM and LIST commands).

** The LIST command returns time with hours and minutes only (without seconds).

Conclusion:
  1. Servers that support MLST/MLSD extension are well-behaved and you
    can safely assume the time values returned be Rebex Ftp object's GetFileDateTime, GetList and GetItems are correct and properly converted to client's local time zone.
  2. Servers that support MLST/MLSD extension also use UTC for values
    returned by MDTM command (if they support it).
  3. Servers that don't support MLST/MLSD extension usually use local
    time zone for value returned by MDTM command, but this is not always the case (MS FTP is an exception).
  4. Servers that don't support MLST/MLSD extension usually use local
    time zone for value returned in directory listings by LIST command (we have not found any exception during our survey).
See more like this: FTP