Similar to pysftp, which offers the preserve_mtime option for get and put (https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connection.get) and (https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connection.put).
Right now, there is no way to use ftputil to preserve the mtime of an upload (although you may use os.utime to modify the mtime of a download, once it is downloaded). This is a big thing I need to do so help is appreciated!
Thank you for your suggestion.
As far as I know, there's no "inherent" way to set the modification timestamp when creating a file or directory, so you have to modify the timestamp after closing the file. For local file operations, as it would apply to
FTPHost.download
, this can be done withos.utime
, as you mention. If I understand correctly, you could easily add the "preserve mtime" functionality inFTPHost.download
by inheriting fromFTPHost
and overwritingdownload
to call the base class method and then callos.utime
on the target file.For uploads, this is more complicated. As far as I know, there's no way in FTP to change the timestamp of a directory or file, apart from changing the timestamp implicitly by writing to the directory or file. pysftp can implement this functionality because it doesn't rely on FTP(S), but uses SFTP as the underlying protocol. FTPS is FTP over a secure connection and can only use FTP commands whereas SFTP is based on SSH and works differently. The only way to support something like
preserve_mtime
for uploads in ftputil would be an FTP server extension which offers an FTP command to change the timestamp. I don't know how many, if any, FTP servers support such an extension.What do you think?
There hasn't been a reply for years and I don't know how to implement this consistently for download and upload (see previous comment). Therefore I close this ticket for now. Feel free to reopen the ticket if there's new information, e. g. about a server extension to change file modification times.