title: How to download only the latest file from SFTP server with Paramiko?
body: <p>I want to write script that connects to my university SFTP server and downloads the latest file with exercises. So far I've changed a little bit the code from Paramiko example, but I do not know how to download the latest file.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>import functools
  import paramiko 
  
  class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy):
      def missing_host_key(self, client, hostname, key):
          return
  
  adress = 'adress'
  username = 'username'
  password = 'password'
  
  client = paramiko.SSHClient()
  client.set_missing_host_key_policy(AllowAnythingPolicy())
  client.connect(adress, username= username, password=password)
  
  def my_callback(filename, bytes_so_far, bytes_total):
      print ('Transfer of %r is in progress' % filename) 
  
  sftp = client.open_sftp()
  sftp.chdir('/directory/to/file')
  for filename in sorted(sftp.listdir()):
      if filename.startswith('Temat'):
          callback_for_filename = functools.partial(my_callback, filename)
          sftp.get(filename, filename, callback=callback_for_filename)
  
  client.close() 
  </code></pre>