Recent

Author Topic: FTP.List, FileTime and seconds  (Read 1878 times)

hebeyer

  • Newbie
  • Posts: 2
FTP.List, FileTime and seconds
« on: February 22, 2020, 06:22:44 pm »
Hello,

I have a little(?) problem with checking a remote file.
If I want to check the date and time of a FTP-File, I use the following function:

Code: Pascal  [Select][+][-]
  1. function ftpfetchdatetime: Boolean;
  2. var
  3. aFTP: TFTPSend;
  4. i: integer;
  5. ftpdatetime: String;
  6. begin
  7.     aFTP := TFTPSend.Create;
  8.     aFTP.UserName := 'USER';
  9.     aFTP.Password := 'PASSWORD';
  10.     aFTP.TargetHost := XXX.XXXXXXXXXXXXXXXX.DE';
  11.    aFTP.TargetPort := '21';
  12.    aFTP.PassiveMode :=true;
  13.   If aFTP.Login then
  14.   begin
  15.    aftp.List('httpdocs/test.dat',false);
  16.    i := 0;
  17.    while i < aftp.FtpList.Count do
  18.      begin
  19.        ftpdatetime := DateTimeToStr(aFTP.FtpList.Items[i].FileTime);
  20.        showmessage(ftpdatetime);
  21.        i:=i+1;
  22.      end;
  23.     aftp.Logout;
  24.     aftp.Free;
  25.   end;
  26. end;      
  27.  

The function gives me a result of e. g. "22.02.2020 18:16:00".
But: The time ist not correct. The filetime on the FTP is "18:16:37". My function always sets the seconds to "00". If I check the filetime with filezilla, it gives me the correct "18:16:37".

Has everyone of you an idea, how to get the right time with seconds?

Greetings from Germany
Henning

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: FTP.List, FileTime and seconds
« Reply #1 on: February 22, 2020, 08:09:09 pm »
You're using Synapse, right? It's difficult to say without seeing the whole response from the server (or at least FTPList.Items[i].OriginalLine) but most probably there is a format mismatch so that synapse can't parse the file's date/time beyond the minutes

Or it may be a bug in Synapse; try to see how it's parsing the server's response.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

hebeyer

  • Newbie
  • Posts: 2
Re: FTP.List, FileTime and seconds
« Reply #2 on: February 22, 2020, 10:54:06 pm »
Yes. I am using synapse.
FTPList.Items.OriginalLine gives me:

-rw-r--r--   1 USER   psacln        305 Feb 22 17:57 httpdocs/test.dat

There are also no seconds in this line  %), but filezilla shows the seconds ...


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: FTP.List, FileTime and seconds
« Reply #3 on: February 23, 2020, 11:00:11 am »
Then either Filezilla is receiving a different format or it's inventing them ;)

Do you really need the seconds?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: FTP.List, FileTime and seconds
« Reply #4 on: February 23, 2020, 11:40:39 am »
Then either Filezilla is receiving a different format or it's inventing them ;)

Do you really need the seconds?
How? This is not correct. The datetime is simply the creation date of the received file, so it includes seconds as well.
Unless you mean the timestamp of the file on the server. That would be different, but still includes seconds.
I don't think it is a bug in Synapse. I think it is merely a formatting issue.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: FTP.List, FileTime and seconds
« Reply #5 on: February 23, 2020, 12:20:13 pm »
Thaddy, he's referring to the FileDate as returned by the server (so yes, the timestamp of the file in the server). Synapse converts the relevant part of the response string to a TDateTime but since (according to a previous post) the server returns only "hour:minutes" in the string, it sets the seconds to zero.

The thing is that Filezilla apparently gets the seconds from somewhere, hence the OP's question.

Or maybe you're right and there's a confusion between the timestamp in the server and the one in the client. In fact, looking at the example's date/time along with the date/time of the original post can lead to that conclusion. Hadn't noticed before :-[
« Last Edit: February 23, 2020, 12:24:29 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: FTP.List, FileTime and seconds
« Reply #6 on: February 23, 2020, 01:28:26 pm »
FTP provides only limited information about a remote file. The LIST command provides an  OS-specific response where the date is usually the last modification time. The MLST/MLSD  commands provide machine-parsable responses. Whether the server returns seconds depends on the FTP server OS and the FTP server software.

[It's been a while since I wrote an FTP client, like 20 years, but that's how I remember it.]

 

TinyPortal © 2005-2018