1
我嘗試使用Python 2.7.1和的paramiko 1.12.0:paramiko.SSHException:通道關閉
connection = paramiko.SSHClient()
connection.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
connection.connect(hostIP, 22, 'd', 'd')
command = 'ls'
(stdin, stdout, stderr) = connection.exec_command(command)
response = stdout.readlines()
errormsg = stderr.read()
但我收到此錯誤信息:
Traceback (most recent call last):<br>
File "./ssh.py", line 32, in <module><br>
(stdin, stdout, stderr) = connection.exec_command(command)<br>
File "/app/python/2.7.1/LMWP3/lib/python2.7/site-packages/paramiko/client.py", line 379, in exec_command<br>
chan.exec_command(command)<br>
File "/app/python/2.7.1/LMWP3/lib/python2.7/site-packages/paramiko/channel.py", line 218, in exec_command<br>
self._wait_for_event()<br>
File "/app/python/2.7.1/LMWP3/lib/python2.7/site-packages/paramiko/channel.py", line 1129, in _wait_for_event<br>
raise e<br>
paramiko.SSHException: Channel closed.
您的連接語法不正確。您應該先搜索谷歌樣本代碼。 – 2013-12-19 14:33:40
你是什麼意思?關於我看到的正確的示例代碼。 – user2968409
我已經連接 connection.connect(hostIP,username ='d',password ='d') 版本。 – user2968409