1

I am trying to create a python script with Paramiko Lib to upload a file on sftp which uses a "ppk" file and a passphrase to connect.

Unfortunately I cant crack the document or found anything which can connect sftp with ppk files.

Additional details: SFTP can manually be connected with Filezilla, WinSCP is not allowing it.

Here is the code I can go upto only. Please help!

k = paramiko.RSAKey.from_private_key_file("/key.ppk")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect( hostname = "ftp.example.com", username = "user", pkey = k,passphrase="somephrase" )

Well that's the least of the problems, I need to upload afterwards when it gets connected.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Ankzious
  • 311
  • 3
  • 18

1 Answers1

1

i suggest that you convert .ppk to .pem ! see : Conver ppk to pem

then like this :

import paramiko
k = paramiko.RSAKey.from_private_key_file("mykey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "www.host.com", username = "ubuntu", pkey = k )
print "connected"
commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ]
for command in commands:
    print "Executing {}".format( command )
    stdin , stdout, stderr = c.exec_command(command)
    print stdout.read()
    print( "Errors")
    print stderr.read()
c.close()
Moetaz Brayek
  • 259
  • 2
  • 9