Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paramiko SFTPClient - Setting missing host key policy?

I know with Paramiko's SSHClient class, you can set a relaxed missing host key policy like so:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

However, I'm opening a file stream via SFTP (not SSHClient), like so:

t = paramiko.Transport((process['hostname'], 22))
keyfile = paramiko.DSSKey.from_private_key_file('./id_dsa')
t.connect(username = 'user', pkey = keyfile)
sftp = paramiko.SFTPClient.from_transport(t)

I couldn't locate anything in the docs for setting a missing host key policy via Transport, or SFTPClient.

Is there any way to achieve the same thing using SFTPClient?

Cheers, Victor

like image 201
victorhooi Avatar asked Dec 13 '12 02:12

victorhooi


1 Answers

One can get SFTP client from SSH client by using open_sftp().

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

sftp = ssh.open_sftp() 
sftp.get('remotefile', 'localfile')

Though I haven't tested this.

like image 199
Vihang D Avatar answered Sep 30 '22 16:09

Vihang D