0

utilizing pysftp, to access a ftp server ( sample code below). I looked through the documentation and tried but ran into an issue with cnopts and learned we need to add the server to known host file . so examples had samples like below. i'm confused on what key we need from server to add it to the known host file. is it the private/public ssh key or something else , ( what does key_data or key represent in sample code below?)

from base64 import decodebytes
import pysftp

cnopts = pysftp.CnOpts(knownhosts='path/to/knownhostsfile')
key_data = "ljfakjfkjskskldjdkj..."
key = paramiko.RSAKey(data=decodebytes(key_data))
cnopts = pysftp.CnOpts()
cnopts.hostkeys.add('example.com', 'ssh-rsa', key)
with pysftp.Connection('host', username='usr', password='pasw', cnopts=cnopts):
    #####
arve
  • 289
  • 6
  • 19

0 Answers0