Last active
January 29, 2020 21:06
-
-
Save josh-gree/3d5e410de03ff4b1ec6cc685553472bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_latest_file_from_sftp(*, local_file_location: str, config: dict) -> None: | |
host = config["host"] | |
password = config["password"] | |
username = config["username"] | |
base_folder = config["base_folder"] | |
conn = pysftp.Connection(host, username=username, password=password) | |
fnames = conn.listdir(base_folder) | |
fnames = [ | |
( | |
fname, | |
datetime.fromtimestamp( | |
conn.lstat(f"{base_folder}/{fname}").st_mtime | |
), | |
) | |
for fname in fnames | |
] | |
most_recent_file = max(fnames, key=lambda x: x[1])[0] | |
logger.info(f"Most recent file: {most_recent_file}") | |
conn.get(f"{base_folder}/{most_recent_file}",local_file_location) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment