Executing command using Paramiko exec_channel on device is not working

后端 未结 1 1714
青春惊慌失措
青春惊慌失措 2020-11-29 12:34

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,         


        
相关标签:
1条回答
  • 2020-11-29 13:15

    If the SSHClient.exec_command does not work, the first think to test is to try (on one line):

    ssh user@host command
    

    That will use the same SSH API (the "exec" channel) as SSHClient.exec_command. If you are on Windows, you can use plink (from PuTTY packages) instead of ssh. If ssh/plink fails too, it indicates that your device does not support the SSH "exec" channel.


    I your case, it seems that the "exec" channel on Brocade SSH server is implemented to support the scp command only.

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

    While it is generally not recommended to use the "shell" channel for command automation, with your server you won't have other option. 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')
    

    See also What is the difference between exec_command and send with invoke_shell() on Paramiko?.

    A similar question on C#/SSH.NET: SSH.NET is not executing command on device.

    0 讨论(0)
提交回复
热议问题