ParallelSSH/ssh-python

Allow more command on single channel.

jkrysl opened this issue · 1 comments

I am unable to use opened channel for another command after running the 1st one. When requesting execution of another command, the issuing command channel.request_exec(cmd) gets stuck.

>>> from ssh.session import Session
>>> from ssh import options
>>> s = Session()
>>> s.options_set(options.HOST, "localhost")
0
>>> s.connect()
0
>>> s.userauth_password("root", "pass")
0
>>> chan = s.channel_new()
>>> chan.open_session()
0
>>> chan.request_exec("uname -r")
0
>>> chan.read()
(22, b'4.18.0-141.el8.x86_64\n')
>>> chan.request_exec("uname -r")
<stuck>

If I try to run the 2nd command on new channel after closing the 1st one, I get SSHError exception:

>>> from ssh.session import Session
>>> from ssh import options
>>> s = Session()
>>> s.options_set(options.HOST, "localhost")
0
>>> s.connect()
0
>>> s.userauth_password("root", "pass")
0
>>> chan = s.channel_new()
>>> chan.open_session()
0
>>> chan.request_exec("uname -r")
0
>>> chan.read()
(22, b'4.18.0-141.el8.x86_64\n')
>>> chan.close()
0
>>> chan = s.channel_new()
>>> chan.open_session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ssh/channel.pyx", line 117, in ssh.channel.Channel.open_session
  File "ssh/utils.pyx", line 74, in ssh.utils.handle_ok_error_codes
ssh.exceptions.SSHError

It even seems that any operation on the newly created channel produces the same SSHError:

>>> chan = s.channel_new()
>>> chan.request_exec("uname -r")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ssh/channel.pyx", line 222, in ssh.channel.Channel.request_exec
  File "ssh/utils.pyx", line 74, in ssh.utils.handle_ok_error_codes
ssh.exceptions.SSHError

So this tells me there was some issue handling the 1st channel. Is there some way around it?

I use libssh-0.9.0-4.el8.x86_64.

Not correct use of SSH protocol. One channel per exec command or use interactive channel.