ftp_stat.parse_ms_time breaks on IIS 7.5 with 4 digit year lines

IIS 7.5 FTP Server displays dates with 4 digit years when in MS-DOS directory style listing mode:

lftp anonymous@localhost:~> ls -l
10-19-2012  03:13PM       <DIR>          SYNCDEST
10-19-2012  03:13PM       <DIR>          SYNCSOURCE

Parser.parse_ms_time in ftp_stat expects a two digit year and breaks on these date lines:

Traceback (most recent call last):
  File "D:\ECLIPSE-WS\ftputilplay\src\ftpsync.py", line 131, in <module>
  File "D:\ECLIPSE-WS\ftputilplay\src\ftpsync.py", line 128, in main
    sync(config_tree, source_host, target_host)
  File "D:\ECLIPSE-WS\ftputilplay\src\ftpsync.py", line 105, in sync
    syncer.sync(source_host.directory, target_host.directory, delete_on_target, use_mtimes, retries, exclude)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_sync.py", line 208, in sync
    if self._source.path.isfile(source_path):
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_path.py", line 111, in isfile
    path, _exception_for_missing_path=False)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\__init__.py", line 896, in stat
    return self._stat._stat(path, _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 625, in _stat
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 579, in __call_with_parser_retry
    result = method(*args, **kwargs)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 544, in _real_stat
    lstat_result = self._real_lstat(path, _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 503, in _real_lstat
    for stat_result in self._stat_results_from_dir(dirname):
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 437, in _stat_results_from_dir
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 377, in parse_line
    st_mtime = self.parse_ms_time(date, time_, time_shift)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 252, in parse_ms_time
    hour, minute, 0, 0, 0, -1) )
OverflowError: mktime argument out of range

when it generates a date of 2012+1900=3912 in these lines:

if year >= 70:
    year = 1900 + year
    year = 2000 + year

I've changed the code to:

if year < 100:
    if year >= 70:
        year = 1900 + year
        year = 2000 + year

This should handle most two and four digit case except for four digit years between 0 and 100. But I'm not really concerned about that old files :). A more stable solution could check for the length of the year input string before handling two digit years.

Best regards,


ftputiluser (unverified)
Assigned to
11 years ago
11 years ago
bug library

schwa (unverified) 11 years ago · edit

Hi Mario, thanks for the report!

I agree with your last statement. In my opinion, it's more straightforward to check the string length of the year part. I'll do it next month, when I have more time.

schwa (unverified) 11 years ago · edit

I've checked in a fix as changeset [3e5e6187eff6fe2348665767bea739393d718585](https://git.sr.ht/~sschwarzer/ftputil/commit/3e5e6187eff6fe2348665767bea739393d718585 "Handle four-digit year in Microsoft directory format (ticket #67).").

Register here or Log in to comment, or comment via email.