Connect to sftp server with host key fingerprint using python 3.0 on Windows

487 Views Asked by At

I am trying to connect to an sftp server using python on Windows. I cannot connect to the server without a hostkey. A lot of options, especially with pysftp ask for hostkey files which apparently aren't generated on Windows.

From what I can see is that I have 3 options:

1) [Most preferred] use a string to generate the required key through python code. But that's always producing errors - some of the code using StringIO doesn't work on Python 3 and the possible workarounds don't seem to work for me. Apparently I am not able to decode the key properly and I have no idea how to check for that. I have tried to generate PKey but I am not sure what I am doing wrong.

2) get the right format of known_hosts file (I have no idea what it should look like and couldn't find any samples online) - and put or add the hostkey there. That way I'd (hopefully) be able to use cnopts to connect to the server.

3) This is a fallback option, if the above two don't work: use python to call powershell script that does the work - I have been successful at this but would like to pass arguments from python script to powershell and then get results/status from powershell back to python.

The most relevant options that I have tried out:

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

Embedding public key as string in Paramiko Application

Using python pysftp package, getting a "SSHException: Bad host key from server" error

What I'd like is a sample string (that would look like the actual thing) and the steps around creating a key from it. Or a sample file that I can use to just plugin the details and run the code.

0

There are 0 best solutions below