Executing command using Paramiko on Brocade switch

倾然丶 夕夏残阳落幕 提交于 2019-12-01 07:52:54

问题


I am trying to use Paramiko to SSH into a Brocade switch and carry out remote commands. The code is as given below:

def ssh_connector(ip, userName, passWord, command):
 ssh = paramiko.SSHClient()
 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 ssh.connect(ip, username=userName, password=passWord, port=22)
 stdin, stdout, stderr = ssh.exec_command(command)
 print stdout.readlines()

ssh_connector(ip, userName, passWord, 'show running-config')

While trying to run the code, I encounter a strange error which is as given below.

Protocol error, doesn't start with scp!

I do not know the cause of the error or whether the SSH connection was successful. Could you please help me with this?


回答1:


The "exec" channel on Brocade SSH server seems to be implemented to support the scp command only. So you cannot use your code with the SSHClient.exec_command.

As you claim to be able to "SSH" to the switch, it seems that the "shell" channel is fully working.

You should be able to use the SSHClient.invoke_shell and write the commands to the channel (= to the shell) using the Channel.send.

channel = ssh.invoke_shell()
channel.send('ls\n')
channel.send('exit\n')


来源:https://stackoverflow.com/questions/30603219/executing-command-using-paramiko-on-brocade-switch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!