开发者

paramiko can't open SFTP connection

开发者 https://www.devze.com 2023-03-22 22:33 出处:网络
I\'m having some trouble opening an SFTP connection with paramiko.My开发者_开发百科 current code is:

I'm having some trouble opening an SFTP connection with paramiko. My开发者_开发百科 current code is:

client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.load_system_host_keys()
client.connect('some.example.com', username="myuser", password="mypassword")
sftp_client = client.open_sftp()
sftp_client.put(my_local_file)

But at the point where I hit client.open_sftp(), I get an exception of "Unable to open channel."

Any idea what might cause this? I've been able to open the connection to the server with a command-line sftp client.

I'm guessing about my invocation here, if anyone can point me to an example, that would be great.


You need to first create and connect to a transport:

transport = Transport((host, port))
transport.connect(username = username, pkey = mykey) # or password = mypassword

Now to can start the SFTP client:

sftp_client = SFTPClient.from_transport(transport)

Then you can

sftp_client.put(my_local_file)

and when you're done

sftp_client.close()
transport.close()
0

精彩评论

暂无评论...
验证码 换一张
取 消