开发者

Using a channel for multiple commands, replys, and interactive commands?

开发者 https://www.devze.com 2023-01-27 18:31 出处:网络
I\'m beginning to learn twisted.conch to automate some tasks over SSH. I tried to modify the sample sshclient.py from http://www.devshed.com/c/a/Python/SSH-with-Twisted/4/ . It runs 1 command after

I'm beginning to learn twisted.conch to automate some tasks over SSH.

I tried to modify the sample sshclient.py from http://www.devshed.com/c/a/Python/SSH-with-Twisted/4/ . It runs 1 command after login and prints captured output.

What I wanted to do is to run a series commands, and maybe decide what to do based on the output.

The problem I ran into is that twisted.conch.ssh.channel.SSHChannel appears to be always closing itself after running a command (such as df -h). The example will sendRequest after channelOpen. Then the channel is always closed after dataReceived no matter what I did.

I'm wondering if this is due to server sending an EOF after the command. And therefore this channel must be closed? Should I just open multiple channels for multiple commands?

Another problem is those interactive commands (such as rm -i somefile). It seems that because the server didn't send EOF, SSHChannel.dataReceived never gets called.开发者_StackOverflow中文版 How do I manage to capture output in this situation, and what do I do to send back a response?


Should I just open multiple channels for multiple commands?

Yep. That's how SSH works.

SSHChannel.dataReceived never gets called

This doesn't sound like what should happen. Perhaps you can include a minimal example which reproduces the behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号