pysftp:如何更新上次修改日期 [英] pysftp: How to update last modified date
问题描述
我试图在对某个文件进行一些处理后将其移动到另一个目录.
I am trying to move a certain file to another directory after doing some process over it.
import pysftp
conn = pysftp.Connection(host = 'host', username = 'user', password = 'password')
remote_src = '/dir1/file1.csv'
remote_dest = '/dir2/archive_file1.csv'
conn.rename(remote_src, remote_dest)
conn.close()
但 LastModified 日期与原始文件相同.
有没有办法在重命名时将 LastModified 日期更新为当前日期?
But the LastModified date remains same as of original file.
Is there a way to update the LastModified date to current date while renaming?
推荐答案
感谢@MartinPrikryl 的回答,我终于达到了我的目的.
Thanks to the answer of @MartinPrikryl I was able to finally achieve my purpose.
pysftp.Connection 有一个属性 sftp_client 根据文档返回活动 paramiko.SFTPClient 对象.
我使用这个属性来调用 paramiko.SFTPClient.时间
pysftp.Connection has a property sftp_client which as per documentation returns the active paramiko.SFTPClient object.
I used this property to call paramiko.SFTPClient.utime
import pysftp
conn = pysftp.Connection(host = 'host', username = 'user', password = 'password')
remote_src = '/dir1/file1.csv'
remote_dest = '/dir2/archive_file1.csv'
conn.rename(remote_src, remote_dest)
# below is the line I added after renaming the file
conn.sftp_client.utime(remote_dest, None)
conn.close()
这篇关于pysftp:如何更新上次修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!