0

I have .ppk file and I am using paramiko module to create connection but it return me error,

Here is my code

import paramiko

hostname = 'sftp.xyz.eu' 
myuser   = 'myusername'
mySSHK   = 'file.ppk'
password = '9SMxT2rAsybsLWt'
sshcon   = paramiko.SSHClient()  # will create the object
sshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # no known_hosts error
sshcon.connect(hostname, username = myuser, password = password, key_filename = mySSHK)
print(sshcon)

it return me this erorr please correct me

sshcon.connect(hostname, username = myuser, password = password, key_filename = mySSHK)
  File "/home/test/Documents/xml_read_ftp/paramiko/client.py", line 446, in connect
    passphrase,
  File "/home/test/Documents/xml_read_ftp/paramiko/client.py", line 764, in _auth
    raise saved_exception
paramiko.ssh_exception.SSHException: No existing session

Now i have convert my file with public_key with puty

Now i am getting this error

self, server_hostkey_name, server_key
  File "/home/test/Documents/xml_read_ftp/paramiko/client.py", line 824, in missing_host_key

paramiko.ssh_exception.SSHException: Server 'sftp.xyz.xyz' not found in known_hosts
Python logix
  • 319
  • 3
  • 14

1 Answers1

0

From my understanding, you are trying to use a PuTTY/Pageant key (file.ppk) while you should be using an OpenSSH key: http://docs.paramiko.org/en/stable/api/client.html#paramiko.client.SSHClient.connect

Try exporting your key to an OpenSSH key and retry with the OpenSSH key.

EDIT

Also, you are using the password argument in connect but it would be better to use the passphrase argument as, I guess, this is the key password.

In case password is the user password, remove it: you are trying to connect with key authentication, you don't need any user password.

StinGer
  • 58
  • 2
  • 5