I am working in an etl (first time), and I need to extract some files from the client's SFTP. The problem I have is that the files number is variable, so I need to check if the file exist and get it, the file format is like "file_YYYY-MM-DD-number-n" where YYYY-MM-DD
is the current date and n
is the number of the file, so if there are 7 files I have to look for:
- file_2019-08-25-number-1
- file_2019-08-25-number-2
Until now I have found that I can do something like this
cnopts = pysftp.CnOpts()
with pysftp.Connection(host=host, port=port, username=username, password=password, cnopts=cnopts) as sftp:
files = sftp.listdir(directory)
How do I find in the files there?