Preserve timestamp with Paramiko

馋奶兔 提交于 2019-12-05 07:11:37

Paramiko does not support that.

You have to explicitly call the SFTPClient.utime after the upload.


Note that pysftp (that internally uses Paramiko) supports preserving the timestamp with its pysftp.Connection.put() method.

You can reuse their implementation (code simplified by me):

local_stat = os.stat(localpath)
times = (local_stat.st_atime, local_stat.st_mtime)

sftp.put(localpath, remotepath)

sftp.utime(remotepath, times)

Similarly for downloads.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!