title: How to check if a file exists in SFTP with pysftp?
body: <p>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 &quot;file_<strong>YYYY-MM-DD</strong>-number-<strong>n</strong>&quot; where <code>YYYY-MM-DD</code> is the current date and <code>n</code> is the number of the file, so if there are 7 files I have to look for:</p>
  <ul>
  <li>file_2019-08-25-number-1</li>
  <li>file_2019-08-25-number-2</li>
  </ul>
  <p>Until now I have found that I can do something like this</p>
  <pre><code>cnopts = pysftp.CnOpts()
  with pysftp.Connection(host=host, port=port, username=username, password=password, cnopts=cnopts) as sftp:
      files = sftp.listdir(directory)
  </code></pre>
  <p>How do I find in the files there?</p>