尝试连接到远程SFTP服务器时,读取全部时出现Paramiko EOF错误

2024-05-19 23:26:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python连接到远程sftp服务器。此服务器由第三方拥有和管理

我可以使用Filezilla和Pycharm的部署工具连接到服务器(因此我认为可以排除防火墙和白名单问题)

我可以使用连接到演示服务器

import paramiko

transport = paramiko.Transport(('test.rebex.net',22))
transport.connect(username='demo',
                  password='password')
print(transport) 

输出:

<paramiko.Transport at 0xf448c50 (cipher aes128-ctr, 128 bits) (active; 0 open channel(s))>

但是,当尝试连接到我需要的服务器时,我会运行:

import paramiko

transport = paramiko.Transport((ftp_server,22))
transport.connect(username=username,password=password)

得到

Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "/venv/lib/python3.7/site-packages/paramiko/transport.py", line 1291, in connect
    self.start_client()
  File "/venv/lib/python3.7/site-packages/paramiko/transport.py", line 660, in start_client
    raise e
  File "/venv/lib/python3.7/site-packages/paramiko/transport.py", line 2055, in run
    ptype, m = self.packetizer.read_message()
  File "/venv/lib/python3.7/site-packages/paramiko/packet.py", line 459, in read_message
    header = self.read_all(self.__block_size_in, check_rekey=True)
  File "S/venv/lib/python3.7/site-packages/paramiko/packet.py", line 303, in read_all
    raise EOFError()
EOFError

我怀疑this问题是相关的,但我还是在调用connect()时得到了相同的错误

我还尝试使用SSHClient对象并对其调用connect(),但得到了相同的错误

我对网络或SSH&;的理论理解很少;SFTP所以,当packetizer试图读取报头以进行初始连接时,服务器似乎没有返回任何信息,但我不明白为什么会这样,或者如何解决。有人能解释这一点吗,或者甚至能给我指出一个帕拉米科的替代品(如果这可能有帮助的话)

编辑2:

import paramiko
import logging

logging.basicConfig()
logging.getLogger("paramiko").setLevel(logging.DEBUG)
ftp_server = 'XXX'
username = 'YYY'
password = 'ZZZ'

transport = paramiko.Transport((ftp_server,22))

输出

DEBUG:paramiko.transport:starting thread (client mode): 0x3d2f510
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_6.6
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_6.6)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-dss', 'ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'chacha20-poly1305@openssh.com', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'chacha20-poly1305@openssh.com', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] client mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group-exchange-sha1
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256-etm@openssh.com
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:EOF in transport thread
Traceback (most recent call last):
  File "<input>", line 11, in <module>
  File "/venv/lib/python3.7/site-packages/paramiko/transport.py", line 1291, in connect
    self.start_client()
  File "/venv/lib/python3.7/site-packages/paramiko/transport.py", line 660, in start_client
    raise e
  File "/venv/lib/python3.7/site-packages/paramiko/transport.py", line 2055, in run
    ptype, m = self.packetizer.read_message()
  File "/venv/lib/python3.7/site-packages/paramiko/packet.py", line 459, in read_message
    header = self.read_all(self.__block_size_in, check_rekey=True)
  File "/venv/lib/python3.7/site-packages/paramiko/packet.py", line 303, in read_all
    raise EOFError()
EOFError

编辑2.1:

从filezilla日志文件成功连接-敏感信息替换为<HOST><USERNAME>

2020-12-11 21:14:36 7151 1 Status: Disconnected from server
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::DoClose(66)
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::ResetOperation(66)
2020-12-11 21:14:36 7151 1 Trace: CFileZillaEnginePrivate::ResetOperation(66)
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::DoClose(66)
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::ResetOperation(66)
2020-12-11 21:14:36 7151 1 Trace: CFileZillaEnginePrivate::ResetOperation(66)
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::DoClose(66)
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::ResetOperation(66)
2020-12-11 21:14:36 7151 1 Trace: CFileZillaEnginePrivate::ResetOperation(66)
2020-12-11 21:14:36 7151 1 Trace: CFileZillaEnginePrivate::ResetOperation(0)
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::SendNextCommand()
2020-12-11 21:14:36 7151 1 Trace: CSftpConnectOpData::Send() in state 0
2020-12-11 21:14:36 7151 1 Status: Connecting to <HOST>...
2020-12-11 21:14:36 7151 1 Trace: Going to execute /private/var/folders/6c/ntd0ljws4m5636vj156l175r0000gn/T/AppTranslocation/6D8907E9-A65E-4E2D-A4EC-65C46A4F1DD1/d/FileZilla.app/Contents/MacOS//fzsftp
2020-12-11 21:14:36 7151 1 Response: fzSftp started, protocol_version=9
2020-12-11 21:14:36 7151 1 Trace: CSftpConnectOpData::ParseResponse() in state 0
2020-12-11 21:14:36 7151 1 Trace: CControlSocket::SendNextCommand()
2020-12-11 21:14:36 7151 1 Trace: CSftpConnectOpData::Send() in state 3
2020-12-11 21:14:36 7151 1 Command: open "<HOST>" 22
2020-12-11 21:14:36 7151 1 Trace: Looking up host "<HOST>" for SSH connection
2020-12-11 21:14:36 7151 1 Trace: Connecting to <HOST_IP> port 22
2020-12-11 21:14:36 7151 1 Trace: We claim version: SSH-2.0-FileZilla_3.49.1
2020-12-11 21:14:36 7151 1 Trace: Remote version: SSH-2.0-OpenSSH_6.6
2020-12-11 21:14:36 7151 1 Trace: We believe remote version has SSH-2 channel request bug
2020-12-11 21:14:36 7151 1 Trace: Using SSH protocol version 2
2020-12-11 21:14:36 7151 1 Trace: Doing Diffie-Hellman group exchange
2020-12-11 21:14:36 7151 1 Trace: Doing Diffie-Hellman key exchange using 2048-bit modulus and hash SHA-1 (unaccelerated) with a server-supplied group
2020-12-11 21:14:37 7151 1 Trace: Server also has ssh-dss host key, but we don't know it
2020-12-11 21:14:37 7151 1 Trace: Host key fingerprint is:
2020-12-11 21:14:37 7151 1 Trace: ssh-rsa 1024 df:d1:18:0e:4d:0b:bc:24:33:84:4c:2a:fe:de:7d:8c yWV/XCKgcAafF1nZTA52HiYK83VBby5W/hELuNchbsA=
2020-12-11 21:14:37 7151 1 Trace: Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
2020-12-11 21:14:37 7151 1 Trace: Initialised HMAC-SHA-1 (unaccelerated) outbound MAC algorithm
2020-12-11 21:14:37 7151 1 Trace: Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
2020-12-11 21:14:37 7151 1 Trace: Initialised HMAC-SHA-1 (unaccelerated) inbound MAC algorithm
2020-12-11 21:14:37 7151 1 Trace: Pageant is running. Requesting keys.
2020-12-11 21:14:37 7151 1 Trace: Pageant has 0 SSH-2 keys
2020-12-11 21:14:37 7151 1 Status: Using username "<USERNAME>". 
2020-12-11 21:14:37 7151 1 Trace: Attempting keyboard-interactive authentication
2020-12-11 21:14:37 7151 1 Trace: Server refused keyboard-interactive authentication
2020-12-11 21:14:37 7151 1 Command: Pass: ************
2020-12-11 21:14:37 7151 1 Trace: Sent password
2020-12-11 21:14:37 7151 1 Trace: Access granted
2020-12-11 21:14:37 7151 1 Trace: Opening main session channel
2020-12-11 21:14:37 7151 1 Trace: Opened main channel
2020-12-11 21:14:37 7151 1 Trace: Started a shell/command
2020-12-11 21:14:37 7151 1 Status: Connected to <HOST>
2020-12-11 21:14:38 7151 1 Trace: Remote working directory is /sftp
2020-12-11 21:14:38 7151 1 Trace: CSftpConnectOpData::ParseResponse() in state 3
2020-12-11 21:14:38 7151 1 Trace: CControlSocket::ResetOperation(0)
2020-12-11 21:14:38 7151 1 Trace: CSftpConnectOpData::Reset(0) in state 3
2020-12-11 21:14:38 7151 1 Trace: CFileZillaEnginePrivate::ResetOperation(0)
2020-12-11 21:14:38 7151 1 Trace: CControlSocket::SendNextCommand()
2020-12-11 21:14:38 7151 1 Trace: CSftpListOpData::Send() in state 0
2020-12-11 21:14:38 7151 1 Status: Retrieving directory listing...
2020-12-11 21:14:38 7151 1 Trace: CSftpChangeDirOpData::Send() in state 0
2020-12-11 21:14:38 7151 1 Trace: CSftpChangeDirOpData::Send() in state 1
2020-12-11 21:14:38 7151 1 Command: pwd
2020-12-11 21:14:38 7151 1 Response: Current directory is: "/sftp"
2020-12-11 21:14:38 7151 1 Trace: CSftpChangeDirOpData::ParseResponse() in state 1
2020-12-11 21:14:38 7151 1 Trace: CControlSocket::ResetOperation(0)
2020-12-11 21:14:38 7151 1 Trace: CSftpChangeDirOpData::Reset(0) in state 1
2020-12-11 21:14:38 7151 1 Trace: CSftpListOpData::SubcommandResult(0) in state 1
2020-12-11 21:14:38 7151 1 Trace: CControlSocket::SendNextCommand()
2020-12-11 21:14:38 7151 1 Trace: CSftpListOpData::Send() in state 2
2020-12-11 21:14:38 7151 1 Trace: CSftpListOpData::Send() in state 3
2020-12-11 21:14:38 7151 1 Command: ls
2020-12-11 21:14:38 7151 1 Status: Listing directory /sftp
2020-12-11 21:14:38 7151 1 Trace: CSftpListOpData::ParseResponse() in state 3
2020-12-11 21:14:38 7151 1 Trace: CControlSocket::ResetOperation(0)
2020-12-11 21:14:38 7151 1 Trace: CSftpListOpData::Reset(0) in state 3
2020-12-11 21:14:38 7151 1 Status: Directory listing of "/sftp" successful
2020-12-11 21:14:38 7151 1 Trace: CFileZillaEnginePrivate::ResetOperation(0)

编辑3:

Paramiko版本1.18.5有效

DEBUG:paramiko.transport:starting thread (client mode): 0x1102df10
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_1.18.5
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_6.6
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_6.6)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-dss', 'ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'chacha20-poly1305@openssh.com', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'chacha20-poly1305@openssh.com', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] client mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-md5
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Attempting password auth...
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
DEBUG:paramiko.transport:EOF in transport thread

我应该在帕拉米科项目中提出这个问题吗


Tags: indebugcomclientparamikotracehmacsha1