Verify host key with pysftp
<p>I am writing a program using pysftp, and it wants to verify the SSH host Key against <code>C:\Users\JohnCalvin\.ssh\known_hosts</code>.</p>
<p>Using PuTTY, the terminal program is saving it to the Registry <code>[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys]</code>.</p>
<p>How do I reconcile the difference between pysftp and PuTTY?</p>
<p>My code is:</p>
<pre class="lang-py prettyprint-override"><code>import pysftp as sftp

def push_file_to_server():
    s = sftp.Connection(host='138.99.99.129', username='root', password='*********')
    local_path = &quot;testme.txt&quot;
    remote_path = &quot;/home/testme.txt&quot;

    s.put(local_path, remote_path)
    s.close()

push_file_to_server()
</code></pre>
<p>The error response I am receiving is:</p>
<pre class="lang-none prettyprint-override"><code>E:\Program Files (x86)\Anaconda3\lib\site-packages\pysftp\__init__.py:61:
UserWarning: Failed to load HostKeys from C:\Users\JohnCalvin\.ssh\known_hosts.  You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None).
 warnings.warn(wmsg, UserWarning)
Traceback (most recent call last): 
  File &quot;E:\OneDrive\Python\GIT\DigitalCloud\pysftp_tutorial.py&quot;, line 14, in &lt;module&gt;
    push_file_to_server()
  File &quot;E:\OneDrive\Python\GIT\DigitalCloud\pysftp_tutorial.py&quot;, line 7, in push_file_to_server
    s = sftp.Connection(host='138.99.99.129', username='root', password='********') 
  File &quot;E:\Program Files (x86)\Anaconda3\lib\site-packages\pysftp\__init__.py&quot;, line 132, in __init__
    self._tconnect['hostkey'] = self._cnopts.get_hostkey(host)   
  File &quot;E:\Program Files (x86)\Anaconda3\lib\site-packages\pysftp\__init__.py&quot;, line 71, in get_hostkey
    raise SSHException(&quot;No hostkey for host %s found.&quot; % host) paramiko.ssh_exception.SSHException: No hostkey for host 138.99.99.129 found.
Exception ignored in: &lt;bound method Connection.__del__ of &lt;pysftp.Connection object at 0x00000222FF3A6BE0&gt;&gt;
Traceback (most recent call last):
  File &quot;E:\Program Files (x86)\Anaconda3\lib\site-packages\pysftp\__init__.py&quot;, line 1013, in __del__
    self.close()  
  File &quot;E:\Program Files (x86)\Anaconda3\lib\site-packages\pysftp\__init__.py&quot;, line 784, in close
    if self._sftp_live:
AttributeError: 'Connection' object has no attribute '_sftp_live'
</code></pre>