我正在尝试连接到我们的一个SFTP服务器以自动生成报告。我们每周从该服务器提取一个文件,但我无法使该连接正常工作。我找不到以下跟踪错误的任何有用参考。任何人都有可能导致此问题的想法吗?
在执行代码2或3秒钟后,我收到一个socket.timeout错误。
import paramiko
cli = paramiko.SSHClient()
cli.set_missing_host_key_policy(paramiko.AutoAddPolicy())
cli.connect(hostname='AHOST', port=21, username="USER", password="PASS")
stdin_, stdout_, stderr_ = cli.exec_command("ls -l ~")
print(stdout_.readlines())
cli.close()
跟踪:
Exception: Error reading SSH protocol banner
Traceback (most recent call last):
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2138, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 367, in readline
buf += self._read_timeout(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 576, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 1966, in run
self._check_banner()
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2143, in _check_banner
"Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Traceback (most recent call last):
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2138, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 367, in readline
buf += self._read_timeout(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 576, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user_name/PycharmProjects/PDD_Report/MAIN/MAIN.py", line 12, in <module>
cli.connect(hostname='A40T', port=21, username="user_name", password="gate001")
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\client.py", line 397, in connect
t.start_client(timeout=timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 587, in start_client
raise e
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 1966, in run
self._check_banner()
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2143, in _check_banner
"Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
答案 0 :(得分:0)
您正在连接到FTP端口21。
SSH / SFTP使用端口22(port
参数的默认值,该值将被您覆盖)。
旁注1:您的问题与SFTP有关。但是,不用SFTPClient
而是使用SSHClient
并执行 shell 命令–与SFTP无关。
注释2:请勿像这样使用AutoAddPolicy
。您
这样做会失去安全性。
参见Paramiko "Unknown Server"。