“Failed to load HostKeys” warning while connecting to SFTP server with pysftp

I believe it’s a bug in pysftp. You get this everytime you use cnopts.hostkeys = None (despite the warning actually suggesting to use that). Anyway, you should not use cnopts.hostkeys = None, you lose security by doing so. For the correct solution, see Verify host key with pysftp. By your reference to key authentication, I … Read more

Python – pysftp / paramiko – Verify host key using its fingerprint

Depending on your needs you can use either of these two methods: In case you need to verify only one specific host key Use ssh-keyscan (or similar) to retrieve the host public key: ssh-keyscan example.com > tmp.pub The tmp.pub will look like (known_hosts file format): example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0hVqZOvZ7yWgie9OHdTORJVI5fJJoH1yEGamAd5G3werH0z7e9ybtq1mGUeRkJtea7bzru0ISR0EZ9HIONoGYrDmI7S+BiwpDBUKjva4mAsvzzvsy6Ogy/apkxm6Kbcml8u4wjxaOw3NKzKqeBvR3pc+nQVA+SJUZq8D2XBRd4EDUFXeLzwqwen9G7gSLGB1hJkSuRtGRfOHbLUuCKNR8RV82i3JvlSnAwb3MwN0m3WGdlJA8J+5YAg4e6JgSKrsCObZK7W1R6iuyuH1zA+dtAHyDyYVHB4FnYZPL0hgz2PSb9c+iDEiFcT/lT4/dQ+kRW6DYn66lS8peS8zCJ9CSQ== Now, you can calculate a fingerprint of … Read more

pysftp vs. Paramiko

pysftp is a wrapper around Paramiko with a more Python-ish interface. pysftp interface does not expose all of the features of Paramiko. On the other hand, pysftp implements more high-level features on top of Paramiko, notably recursive file transfers. pysftp has not been updated since 2016, so it seems abandoned project. It has also some … Read more

Python pysftp get_r from Linux works fine on Linux but not on Windows

Indeed, pysftp get_r does not work on Windows. It uses os.sep and os.path functions for remote SFTP paths, what is wrong, as SFTP paths always use a forward slash. But you can easily implement a portable replacement. import os from stat import S_ISDIR, S_ISREG def get_r_portable(sftp, remotedir, localdir, preserve_mtime=False): for entry in sftp.listdir_attr(remotedir): remotepath = … Read more

Verify host key with pysftp

The pysftp has some bugs regarding host key handling, as described below. It also seems that the pysftp project was abandoned. Consider using Paramiko directly instead. The pysftp is just a wrapper on top of Paramiko and it does not add anything really significant. See pysftp vs. Paramiko. For handling of host keys in Paramiko, … Read more