The method ftputil.stat.Parser.parse_unix_time
is responsible for
parsing unix timestamps in directory lines. The code contains the
following heuristics to guess the correct year on the server side:
# Try the current year
year = time.localtime()[0]
st_mtime = self._mktime((year, month, day, hour, minute, 0, 0, 0, -1))
The problem with this code is that it implicitly assumes that the year on the client side is the same as the year on the server side. This assumption is wrong if the years actually differ. For example, if the directory line on the server is
-rw-r--r-- 1 45854 200 4604 Jan 01 01:49 index.html
but the local time on the client side is 2019-12-31T23:49, the code
assumes that the January in the directory line refers to the previous
January 1st from the point of view of the client. Consequently, the
st_mtime
of the stat result is about one year in the past for a file
that was just created.
The bug should be fixed in [6ed5887149b5528549ed43de7bcc6d9b6e29fdb4](https://git.sr.ht/~sschwarzer/ftputil/commit/6ed5887149b5528549ed43de7bcc6d9b6e29fdb4 "Fix bug around year change (ticket #131) The previous code failed ...").
The fix [6ed5887149b5528549ed43de7bcc6d9b6e29fdb4](https://git.sr.ht/~sschwarzer/ftputil/commit/6ed5887149b5528549ed43de7bcc6d9b6e29fdb4 "Fix bug around year change (ticket #131) The previous code failed ...") also fixes the bug that the time shift wasn't taken into account. Commit 3ca470400fcfb8d5ce361bc4fb1a27e84f1e8186 fixes the same type of bug for the MS parser.