Paramiko挂在ssh.open_sftp()上

时间:2015-07-02 16:28:06

标签: python ssh sftp paramiko

我尝试运行以下脚本:

import paramiko
import os

host, port, user, passw, key = .... 

transport = paramiko.Transport((host, port))
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

private_key_file = key
paramiko.util.log_to_file("filename.log")
xSx_key = paramiko.RSAKey.from_private_key_file(private_key_file,None)
transport.connect(username = user, password=passw, pkey = xSx_key)
ssh.connect(host, username=user, password=passw, pkey=xSx_key, port=port) 


ftp = ssh.open_sftp()
files = ftp.listdir()

不幸的是,这在open_sftp()调用期间会挂起。如果我随后做了一个KeyboardInterrupt,我得到以下stacktrace:

  ftp = ssh.open_sftp()
  File "build\bdist.win-amd64\egg\paramiko\client.py", line 379, in open_sftp
  File "build\bdist.win-amd64\egg\paramiko\transport.py", line 811, in open_sftp_client
  File "build\bdist.win-amd64\egg\paramiko\sftp_client.py", line 128, in from_transport
  File "build\bdist.win-amd64\egg\paramiko\transport.py", line 615, in open_session
  File "build\bdist.win-amd64\egg\paramiko\transport.py", line 726, in open_channel
  File "C:\Anaconda\lib\threading.py", line 620, in wait
    self.__cond.wait(timeout)
  File "C:\Anaconda\lib\threading.py", line 358, in wait
    _sleep(delay)
KeyboardInterrupt

paramiko日志文件显示以下内容,

DEB [20150702-17:22:11.519] thr=1   paramiko.transport: starting thread (client mode): 0x32a00f0L
INF [20150702-17:22:11.604] thr=1   paramiko.transport: Connected (version 2.0, client SSHD)
DEB [20150702-17:22:11.686] thr=1   paramiko.transport: kex algos:[u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1', u'diffie-hellman-group-exchange-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes256-cbc', u'aes192-cbc', u'aes128-cbc', u'3des-cbc'] server encrypt:[u'aes256-cbc', u'aes192-cbc', u'aes128-cbc', u'3des-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none', u'zlib'] server compress:[u'none', u'zlib'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20150702-17:22:11.687] thr=1   paramiko.transport: Ciphers agreed: local=aes128-cbc, remote=aes128-cbc
DEB [20150702-17:22:11.687] thr=1   paramiko.transport: using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-cbc, remote aes128-cbc; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20150702-17:22:12.020] thr=1   paramiko.transport: Switch to new keys ...
DEB [20150702-17:22:12.026] thr=2   paramiko.transport: Attempting public-key auth...
DEB [20150702-17:22:12.188] thr=1   paramiko.transport: userauth is OK
INF [20150702-17:22:14.894] thr=1   paramiko.transport: Auth banner: <cut>

INF [20150702-17:22:15.078] thr=1   paramiko.transport: Authentication continues...
DEB [20150702-17:22:15.078] thr=1   paramiko.transport: Methods: [u'password', u'publickey', u'keyboard-interactive']
DEB [20150702-17:22:15.168] thr=3   paramiko.transport: starting thread (client mode): 0x33263c8L
INF [20150702-17:22:15.253] thr=3   paramiko.transport: Connected (version 2.0, client SSHD)
DEB [20150702-17:22:15.335] thr=3   paramiko.transport: kex algos:[u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1', u'diffie-hellman-group-exchange-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes256-cbc', u'aes192-cbc', u'aes128-cbc', u'3des-cbc'] server encrypt:[u'aes256-cbc', u'aes192-cbc', u'aes128-cbc', u'3des-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none', u'zlib'] server compress:[u'none', u'zlib'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20150702-17:22:15.335] thr=3   paramiko.transport: Ciphers agreed: local=aes128-cbc, remote=aes128-cbc
DEB [20150702-17:22:15.335] thr=3   paramiko.transport: using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-cbc, remote aes128-cbc; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20150702-17:22:15.671] thr=3   paramiko.transport: Switch to new keys ...
DEB [20150702-17:22:15.680] thr=2   paramiko.transport: Adding ssh-rsa host key for [<cut>]:<cut>: e5025a02b8ca851f7f0a2d173161400c
DEB [20150702-17:22:15.680] thr=2   paramiko.transport: Trying SSH key 4e85b76b311684e139c597cbab111fef
DEB [20150702-17:22:15.841] thr=3   paramiko.transport: userauth is OK
INF [20150702-17:22:19.246] thr=3   paramiko.transport: Auth banner: <cut>

INF [20150702-17:22:19.426] thr=3   paramiko.transport: Authentication continues...
DEB [20150702-17:22:19.427] thr=3   paramiko.transport: Methods: [u'password', u'publickey', u'keyboard-interactive']
DEB [20150702-17:22:19.438] thr=2   paramiko.transport: [chan 0] Max packet in: 32768 bytes
WAR [20150702-17:22:19.526] thr=3   paramiko.transport: Oops, unhandled type 3
DEB [20150702-17:22:35.707] thr=1   paramiko.transport: EOF in transport thread
DEB [20150702-17:22:35.726] thr=3   paramiko.transport: EOF in transport thread

我想知道“未处理的3型”是否有任何提示?我尝试连接的服务器需要user,pass和keyfile。

任何建议都会非常感激,因为我在这里不知所措。请注意,我可以使用例如WinSCP连接到此服务器而没有问题。

谢谢!

-Joris。

0 个答案:

没有答案