首页 > 解决方案 > 您可以使用 Paramiko SSHClientInteraction 通过 SSH 通道/连接发送的命令长度是否有限制?

问题描述

我是 Paramiko 的新手,并且尝试了多种方法来完成一项非常基本的任务。此时,我要做的就是在 APC UPS 上执行命令。在我的测试中,我发现我可以成功执行一个命令,只要命令的长度不超过 20 个字符。

这是我的代码 -

import paramiko
from paramiko_expect import SSHClientInteraction

host = "xxx.xxx.xxx.xxx"  # UPS
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username='e164468', password='********', banner_timeout=60)

chan = SSHClientInteraction(ssh, timeout=2, display=True)
prompt = 'apc>'
command = 'cipher -rsake disable'
chan.expect(prompt)
chan.send(command)
chan.expect(prompt)
output_raw = chan.current_output_clean
chan.close()
ssh.close()
print ("Here is your output - ")
print(output_raw)

我需要远程执行的命令是'cipher -rsake disable'。当我运行它时,我在终端中得到的是 -

apc>cipher -rsake disablEXCESS TIME RECV_READY TIMEOUT, did you expect() before a send()

如果我从命令中删除 disable 参数,它会按预期工作。无论我尝试了什么,只要命令超过 20 个字符,我都会得到这种行为。

我不确定测试的有效性,但我手动 ssh 到 UPS,可以输入我需要的任何命令,它可以工作。

任何帮助将不胜感激!

标签: pythonsshparamikosend

解决方案


推荐阅读