Re: problems with dates

Giganews Newsgroups
Subject: Re: problems with dates
Posted by:  Remy Lebeau (TeamB) (gambit47.no.spam@no.spam.yahoo.com)
Date: Fri, 2 Jan 2004

"Marc Pelletier" <marc@goldak.stopspam.ca> wrote in message
news:Xns94648F15F18CEmpgex…@66.221.34.76...

> I use the TIdFTPListItem.ModifiedDate property to compare with
> the local file and update it if the remote version is newer.

WarFTP supports the MDTM command, which is much more standardized then
retreiving the ModifiedData from the directory listing (which is not a
standardized operation).  The MDTM command sends back the file's timestamp
in a specific GMT format, so can can then convert the local file's time to
GMT as well and then compare the two values as needed.

If you are using Indy 9, you will have to use TIdFTP's Quote() method to
send the MDTM command manually, since TIdFTP does not natively support MDTM.
Have a look at the following page for the format of the MDTM command:

  http://www.southrivertech.com/support/titanftp/webhelp/mdtm.htm

For example:

    var
        LYear, LMonth, LDay, LHour, LMin, LSec, LMSec : Integer;
        LBuffer : String;
        RemoteFileTime: TDateTime;
    begin
        //...
        if IdFTP1.Quote('MDTM /somefile.ext') = 213 then
        begin
            LBuffer := LastCmdResult.Text[0];
            LYear := StrToIntDef( Copy(LBuffer, 1, 4), 0 );
            LMonth := StrToIntDef( Copy(LBuffer, 5, 2), 0 );
            LDay := StrToIntDef( Copy(LBuffer, 7, 2), 0 );
            LHour := StrToIntDef( Copy(LBuffer, 9, 2), 0 );
            LMin := StrToIntDef( Copy(LBuffer, 11, 2), 0 );
            LSec := StrToIntDef( Copy(LBuffer, 13, 2), 0 );
            IdGlobal.Fetch( LBuffer, '.' );
            LMSec := StrToIntDef( LBuffer, 0 );

            RemoteFileTime := EncodeDate( LYear, LMonth, LDay ) +
EncodeTime( LHour, LMin, LSec, LMSec ) + IdGlobal.OffSetFromUTC;

            // use RemoteFileTime as needed ...
        end;
        //...
    end;

If, on the other hand, you are using Indy 10, TIdFTP has support for MDTM
via a new FileDate() method, ie:

    var
        RemoteFileTime: TDateTime:
    begin
        //...
        RemoteFileTime := IdFTP1.FileDate('/somefile.ext', False);
        // use RemoteFileTime as needed ...
        //...
    end;

Gambit

Replies

In response to

problems with dates posted by Marc Pelletier on Fri, 2 Jan 2004