~sschwarzer/ftputil#105: 
option to preserve mtime on upload and download

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!

Status
RESOLVED WONT_FIX
Submitter
ftputiluser (unverified)
Assigned to
No-one
Submitted
7 years ago
Updated
7 years ago
Labels
enhancement library

schwa (unverified) 7 years ago · edit

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 with os.utime, as you mention. If I understand correctly, you could easily add the "preserve mtime" functionality in FTPHost.download by inheriting from FTPHost and overwriting download to call the base class method and then call os.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?

schwa (unverified) 4 years ago · edit

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.

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