1

I would like to ask if Delphi Indy ftp idFTP.GET can preserve the file's created and modified date? If not, how can I accomplish this?

Thanks!

rardark
  • 41
  • 5

1 Answers1

3

TIdFTP.Get() creates a new local file, so the OS is going to assign the current date/time to that file by default. To assign the remote file's timestamp to the local file, you will have to retrieve the remote file's timestamp using either TIdFTP.FileDate(), TIdFTP.List(), or TIdFTP.ExtListDir(), and then apply the timestamp to the local file using platform-specific APIs, such as SetFileTime() on Windows, utimensat()/futimens() on Linux, etc.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    While this is true (and so very obvious): [HOW TO GET: Time Zone Setting of FTP Server?](https://stackoverflow.com/a/3340299/4299358) – AmigoJack Feb 11 '23 at 00:38
  • 1
    @AmigoJack that post is old. There are commands now to determine an FTP server's local timezone, and `TIdFTP` queries that by default, see the `TIdFTP.TZInfo` property. Also, `TIdFTP.FileDate()` and modern directory listings are able to provide timestamps as UTC, so you don't always need the server's timezone anyway. – Remy Lebeau Feb 11 '23 at 16:43