Search code examples
pythonsshparamiko

Difference between exec_command in client and channel of Paramiko?


In Python package Paramiko, there exists exec_command method in channel.py and client.py, what is the difference between them?


Solution

  • The Channel is a low-level API that you should not use in general.

    The SSHClient.exec_command calls Channel.exec_command and after that creates stdin/stdout/stderr objects and returns them as 3-touple. With Channel you would have to create these objects yourself (as without them the Channel.exec_command is useless).

    See also Paramiko exec_command fails with 'NoneType' object is not iterable.

    Additionally, the SSHClient.exec_command has get_pty and environment parameters that trigger Channel.get_pty() and Channel.update_environment respectively.

    Check SSHClient.exec_command source code.