'How to curl -R to preserve file time?

When I use curl -R to download a file from an FTP server, it seems that the time is not the same on the server and on the local machine.

$ lftp -e 'rels -l usa.txt;exit'  -u 'shortstock:' ftp://ftp3.interactivebrokers.com
-rw-r--r--    1 ftp      ftp       1232043 Mar 09 19:15 usa.txt
$ curl -R -O -s -u 'shortstock:' ftp://ftp3.interactivebrokers.com/usa.txt
$ TZ=America/New_York stat -c %w$'\n'%x$'\n'%y$'\n'%z usa.txt
2022-03-09 14:15:31.000000000 -0500
2022-03-09 14:15:31.000000000 -0500
2022-03-09 14:15:31.000000000 -0500
2022-03-09 19:28:14.620714215 -0500

How can I get the local version have the same time as the server version?



Solution 1:[1]

The times are the same.

The files on the server GMT and your system appears to be America/New_York, which is currently 5 hours behind GMT. 14:15 in New York (-0500) is the same time as 19:15 (-0000) as displayed using your local time zone.

EDIT:

Example

lftp -e 'rels -l usa.txt;exit'  -u 'stockdown:' ftp://ftp3.interactivebrokers.com
-rw-r--r--    1 ftp      ftp       1207583 Mar 13 12:15 usa.txt 

curl -R -O -s -u 'stockdown:' ftp://ftp3.interactivebrokers.com/usa.txt

TZ=America/Los_Angeles stat -c %w$'\n'%x$'\n'%y$'\n'%z usa.txt
-
2022-03-13 05:15:30.000000000 -0700
2022-03-13 05:15:30.000000000 -0700
2022-03-13 09:23:22.370307478 -0700

TZ=America/New_York stat -c %w$'\n'%x$'\n'%y$'\n'%z usa.txt
-
2022-03-13 08:15:30.000000000 -0400
2022-03-13 08:15:30.000000000 -0400
2022-03-13 12:23:22.370307478 -0400

TZ=GMT stat -c %w$'\n'%x$'\n'%y$'\n'%z usa.txt
-
2022-03-13 12:15:30.000000000 +0000
2022-03-13 12:15:30.000000000 +0000
2022-03-13 16:23:22.370307478 +0000

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1