title: Python Paramiko directory walk over SFTP
body: <p>How to do <code>os.walk()</code> but on another computer through SSH? The problem is that <code>os.walk()</code> executes on a local machine and I want to ssh to another host, walk through a directory and generate MD5 hashes for every file within.</p>
  <p>What I wrote so far looks like this (below code) but it doesn't work. Any help would be greatly appreciated.</p>
  <pre><code>try:
      hash_array = []
      ssh = paramiko.SSHClient()
      ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      ssh.connect('sunbeam', port=22, username='xxxx', password='filmlight')
  
      spinner.start()
      for root, dirs, files in os.walk(_path):
          for file in files:
              file_path = os.path.join(os.path.abspath(root), file)
              
              #  generate hash code for file
              hash_array.append(genMD5hash(file_path))
              
              file_nb += 1
      spinner.stop()
      spinner.ok('Finished.')
  
      return hash_array
  except Exception as e:
      print(e)
      return None
  finally:
      ssh.close() 
  </code></pre>