Preserving the time and date
of files uploaded to a FTP server

The problem

The original FTP specification and recent extensions to it do not include any way to preserve the time and data for files uploaded to a FTP server.
The modification time of a file is often used by users sorting directory listings or by scripts deciding if one file is newer than another file.
A mechanism is need where files can be uploaded to a server and the time and date preserved.

Two systems to preserve the time and date are currently used by some FTP cliets and FTP servers. These are the SITE UTIME and MDTM commands.
Both of these have problems. SITE UTIME this implemented in different ways by different applications.
MDTM is ambiguous if files with filenames containing dates are present.

The solution
The solution is to define a new command, submit it to IETF as a Internet Draft and ultmatly produce a RFC.
This web page defines two alternative commands and acts as an initial starting point for the Internet Draft.
The new commands SRFT (Set Remote File Time) and MODA (Modify Attributes) are defined.
One of these two commands will be selected.


SITE commands

The FTP command "SITE" can be used to extend the FTP protocol and to allow site specific commands to be carried out by the FTP server.

Several FTP implementation have created a SITE UTIME command which lets a FTP client set the time and date attributes of a file on the server.
The command gets its name from the C library function called utime which sets access time and modification time of a file.
The purpose of SITE commands is to allow FTP clients and servers to implement extra commands as they see fit and as such there is no single standard for these commands.
 

An investigation of various open source FTP applications and conversations with FTP authors have revealed three flavours of the SITE UTIME command in common usage

Type 1

 
SITE <sp> UTIME <sp> filename <sp> datetime1 <sp> datetime2 <sp> datetime3 <sp> UTC

    filename is the name of the file to modify
    datetime#1 is the file's access time, converted to UTC and in the format YYYYMMDDhhmmss
    datetime#2 is the file's modification time, converted to UTC and in the format YYYYMMDDhhmmss
    datetime#3 is the file's creation time, converted to UTC and in the format YYYYMMDDhhmmss

Unfortunately the filename is sent as the first parameter and this causes problems when there is a space within the filename. FTP servers need to parse the command line carefully. For example in the case of SITE UTIME data log.txt 20050101123000 20050101123000 20050101123000 UTC, an incorrect parser would identify the 2nd parameter (ie datetime1) as "log.txt"

Type 2

 
SITE <sp> UTIME <sp> datatime <sp> filename

    filename is the name of the file to modify
    datetime is the file's modification time and in the format YYYYMMDDhhmmss

Type 3

 
SITE <sp> UTIME <sp> datatime <sp> filename

    filename is the name of the file to modify
    datetime is the file's modification time and in the format YYYYMMDDhhmm. Note it does not include the seconds.

 

 

Type 1 commands are used by the lftp client, the ncftp client (version3), the wzdFTPd server and the Crush FTP server
Type 2 commands are used by the gftp client
Type 3 commands are used by the ProFTPd client

In addition NFTP, OS/2's FTPServer and the Perl Net::FTPServer all implement a SITE UTIME command but the parameters are not known at this time.

 

Announcing the SITE UTIME command

Some FTP servers report their support for a SITE UTIME in response to SITE HELP or HELP SITE commands.


MDTM command overloading

The MDTM command was introduced with the FTP Extensions Internet Draft. It is used by a client to read the modification time of a file on the server.
It has since been used by several FTP clients and several FTP servers to set the modification time of a file on the server.

To read the modification the following command is used:-
            MDTM <sp> filename
This returns the files time and date in YYYYMMDDhhmmss format.

To set the modification time of a file on the server, the following command is used:-
        MDTM <sp> YYYYMMDDhhmmss <sp> filename

The problem with using MDTM to set the time of a file is the command is ambiguous.

For example. The command MDTM 20050414173042 log.txt could mean either
   
    a) GET the time and date of a file called "20050414173042 log.txt"
OR    b) Try to SET the time and date of a file called log.txt to 14th April 2005, 17:30.42

Announcing the MDTM command
The presence of the MDTM command to read the time and date of a file on the server is announced in the FEAT command.
FTP servers which allow MDTM to set the time and date of a file on the server are unable to announce this and FTP clients must simply try the command to see what the response is.


SRFT. A New FTP command to Set Remote File Time

This proposed FTP command is a direct replacement for the overloaded use of MDTM.
The command has the following structure

    SRFT <sp> datetime <sp> filename

    filename is the name of the file to modify
    datetime is the file's modification time and in the format YYYYMMDDhhmmss[.mmmm]. The full definition for this is given below.

FTP clients which use MDTM to change the data and time of a file can simply issue the SRFT command instead. The syntax is identical to the overloaded MDTM command making the change very simple to implement.
 

Announcing the SRFT command

The SRFT command will be announced in the response to the FEAT command so that FTP clients can automatically detect that a server supports this command


MODA. A New FTP command to Modify the Attributes of a Remote File

This proposed FTP command is based on the same concepts as the proposed MLST command and allows a wide range of file attributes to be set by a client.

FTP servers will respond to the FEAT command with a string containing a list of attributes that the server can set.
For example the following response indicates a server can have the modification date/time, creation date/time and file accessed data/time attributes updated.
        MODA modify*;created*;accessed*;

In this example, the response indicates a server can only have the modification date/time and accessed date/time set. This would be the case with a Unix based FTP server which does not have a notion of file creation dates.
        MODA modify*;accessed*;

 

FTP clients can then issue MODA commands with the correct parameters to set specific attributes on the server.
The syntax is

    MODA <sp> [list of attributes to set of the form attribute name = attribute value, separated by semi-colons] <sp> filename

The modify, created and accessed attributes will take a date/time of the format YYYYMMDDhhmmss[.mmmm]. The full definition for this is given below.

Examples

    The following command will set the modification date of a file
        MODA modify=20050414132045; thefile.txt

    The following command will set the modification date and created date of a file
        MODA modify=20050414132045;created=20041225081530 thefile.txt

 

The FTP client must only issue a MODA command which the FTP server has already announced via the FEAT command. If a Windows FTP client issues a MODA command with a created attribute to a Unix server which has not included created*; in its response to FEAT, the server should reject the command.

Note that Microsoft Windows systems support the file creation dates but Unix systems do not support this.

 

 

Other attributes
The MODA command allows for other attributes to be defined, either formally or as local extensions as defined in the MLST definition.
Additional attributes could in include file read/write premissions, owner settings and group settings. This would allow a single command to implement SITE CHOWN, SITE CHGRP and SITE CHMOD commands.

However the primary aim of this command (at this time) to to allow the modification date/time of uploaded files to be set.


Date and Time Parameter Format

The date/time is in the format

        YYYYMMDDhhmmss[.mmmm]

The time and date will be converted to UTC. Clients and Servers can then adjust the time for their local Time Zone accordingly.
YYYY = year (0000 to 9999), MM = month (01 to 12), DD = day (01 to 31),
hh = hours (00 to 23), mm = minutes (00 to 59) and ss = seconds (00 to 59).
The Year, Month, Day, Hours, Minutes and Seconds fields must all be included.

[.mmmm] is an optional sequence of digits to support milliseconds.
It is an arbitrary length and not limited to 4 significant digits.

Servers should accept times both with and without milliseconds. If their file system does not support milliseconds, this part of the datetime can be ignored.
Clients can send a time with or without milliseconds, depending on their file system and implementation.

It is anticipated that most implementations will not make use of the milliseconds part of the time/date.

 


 

 

Consultation Period

The author of this report, Roger Hardiman, would like to hear from interested parties regarding the two proposed commands to see which will benefit the FTP community. Conversations with the authors of lftp, wzdFTPd, ProFTPd, Filezilla and CoreFTP have already begun and initial feedback is that a new documented command to set the modification time of files would be accepted and implemented.

(c) Roger Hardiman. May 2005, 2007, 2009