I know how to connect with SFTP server and get the newest file:
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)
Now I need to find in /path
the folder whose name has yesterday's timestamp in format dd.mm.yyyy
and download the newest file from it.