2

我正在尝试连接到pysftp用于传输文件的服务器。每当我跑步

con = pysftp.Connection('ftp.abc.com', username='user', password='my_pass')

我得到SSHException说法不兼容的 ssh 服务器,这很可能是由于使用(或未使用)压缩。

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pysftp.py", line 162, in __init__
    self._transport.connect(username=username, password=password)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 978, in connect
    self.start_client()
  File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 406, in start_client
    raise e
SSHException: Incompatible ssh server (no acceptable compression) [] [] ('none',)

服务器本身没有问题,因为当我运行时sftp -v ftp.abc.com,我得到以下输出:

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
...
debug1: Connection established.
...
...
...
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version JSCAPE
debug1: no match: JSCAPE
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client 3des-cbc hmac-md5 zlib
debug1: kex: client->server 3des-cbc hmac-md5 zlib
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: ...
debug1: Host ... is known and matches the RSA host key.
debug1: Found key in /home/.../.ssh/known_hosts:3
debug1: ssh_rsa_verify: signature correct
debug1: Enabling compression at level 6.
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password
debug1: Next authentication method: password

输入密码后它工作正常。

我做了一些阅读并尝试在没有压缩的情况下 sftping 到服务器,但我做不到。ssh_config即使在我更改文件并在命令行中指定后,它也总是启用压缩-oCompression=no

那么,如何在不使用压缩的情况下进行连接,更重要的是,有没有办法使用压缩级别设置为 6 的 pysftp?

4

1 回答 1

0

我整理了paramiko部分。

我下载了源代码,然后我不得不将其更改_preferred_compressionzlib. 默认设置为none

在 paramiko/transport.py 的第 102 行,我更改了行

_preferred_compression = ('none',)

_preferred_compression = ('zlib',)

它奏效了,但我不知道为什么 paramiko 无法与之谈判。

关于不压缩运行的部分sftp仍然得到解答。任何帮助将不胜感激。

于 2014-12-27T12:52:14.650 回答