Paramiko: Method To Open And Return An Sftp Conneciton
I want to write a method that takes an IP, username, and password, and returns an open SFTP connection to that server. Here's the code I have, using paramiko: def open_sftp_connec
Solution 1:
You need access to both the ssh and sftp instances.
def open_sftp_connection(ip, user, passwd):
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, 22, user, passwd)
assert ssh.get_transport().is_active(), 'Failed to connect to server'
return ssh, ssh.open_sftp()
ssh, sftp = open_sftp_connection(ip, user, passwd)
print sftp.get_channel().get_transport().is_active()
Post a Comment for "Paramiko: Method To Open And Return An Sftp Conneciton"