title: Download the latest file according to timestamp in file name from SFTP server
body: <p>I'm trying to get latest new file in a directory of remote Linux server. The file in SFTP server is created every 4 hours and the file have specific name start with <code>filegen_date_hour.json</code> as per example below. In this case latest file 'filegen_20200101_0800.json' need to be transferred to my local directory.</p>
  
  <pre><code>filegen_20200101_0000.json
  filegen_20200101_0400.json
  filegen_20200101_0800.json
  </code></pre>
  
  <p>I use Python 3 code below, but got error </p>
  
  <pre><code>latestFile = max(listFile, key=os.path.getctime)
  ValueError: max() arg is an empty sequence
  </code></pre>
  
  <p>SFTP code below</p>
  
  <pre><code>myHostname = "192.168.100.10"
  myUsername = "user"
  myPassword = "password"
  
  cnopts = pysftp.CnOpts()
  cnopts.hostkeys = None
  
  with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts) as sftp:
      with sftp.cd('/home/operation/genfiles/'):             
          fileDir = '/home/operation/genfiles/filegen_*.json' 
          **#file have specific pattern with filegen_*.json**
          listFile = glob.glob(fileDir)
          latestFile = max(listFile, key=os.path.getctime)
          sftp.get(latestFile)         
  
  </code></pre>
  
  <p>Appreciate help on this matter. Thank you for your response and help.</p>