gpt4 book ai didi

python - 使用不压缩或指定压缩级别的 pysftp

转载 作者:行者123 更新时间:2023-12-02 14:09:18 24 4
gpt4 key购买 nike

我正在尝试使用 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?

最佳答案

我整理了paramiko部分。

我下载了source code然后我不得不更改 _preferred_compressionzlib .它设置为 none默认情况下。

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

_preferred_compression = ('none',)


_preferred_compression = ('zlib',)

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

还有关于运行的部分 sftp没有压缩仍然保持回答。
任何帮助将不胜感激。

关于python - 使用不压缩或指定压缩级别的 pysftp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27664571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com