【发布时间】:2021-05-07 13:24:26
【问题描述】:
我知道如何连接 SFTP 服务器并获取最新文件:
with pysftp.Connection(host=host, username=user, password=pass, cnopts=cnopts) as sftp:
print("Connected")
sftp.cwd('/path')
latest = 0
latestfile = None
for fileattr in sftp.listdir_attr():
if fileattr.filename.startswith('Name') and fileattr.st_mtime > latest:
latest = fileattr.st_mtime
latestfile = fileattr.filename
if latestfile is not None:
localFilePath = '//path/to/download/file.txt'
sftp.get(latestfile, localFilePath)
现在我需要在/path 中找到名称为dd.mm.yyyy 格式的昨天时间戳的文件夹,并从中下载最新的文件。
【问题讨论】:
标签: python python-3.x sftp pysftp