[Twisted-Python] how to get extReceived call from SSHCommandClientEndpoint

Sereysethy TOUCH touch.sereysethy at gmail.com
Sat Apr 6 11:12:17 MDT 2019


Hi Jean-Paul,

No I dont want it to be mixed with stdout stream, it should be separated
from normal stdout, so that I know it is an error.

To be honest, I am pretty to new to Twisted concept, there are things that
I have not familiar with yet. Actually I can also implement a low level ssh
client (which I already did), but as SSHCommandClientEndpoint is already
available, so I want to use it straight away. But when I dived in the
source code, the _CommandChannel only implements dataReceived but not
extReceived.

For your suggestion on using ProcessEndpoint how can I use it for my SSH
client?

In my extReceived I just deliver what I got to the extReceived of method
protocol, it is exactly the same as Twisted implements dataReceived:

class CommandChannel(_CommandChannel):
    def extReceived(self, dataType, data):
        """
        When the command's extended data (usually standard error) arrives,
        deliver it to the protocol instance.

        @type dataType: L{int}
        @type data:     L{str}
        """
        self._protocol.extReceived(dataType, data)

I have two other questions since you are here

1) how can we execute command like more or less which is an interactive
command?
2) how to request a pty to ssh server?

Thanks,
Sethy



On Fri, Apr 5, 2019 at 8:13 PM Jean-Paul Calderone <
exarkun at twistedmatrix.com> wrote:

> On Fri, Apr 5, 2019 at 2:08 PM Sereysethy TOUCH <
> touch.sereysethy at gmail.com> wrote:
>
>> Hi Sean,
>>
>> Yes it is a method of SSHChannel, but when I read the source code, the
>> _CommandChannel only implements dataReceived which calls protocol's method
>> but it does not implement extReceived.
>>
>> When you suggest to call it like that (self.transport.conn.channels[0].extReceived()),
>> how do I know when extended data is received?
>>
>> For now I have subclassed _CommandChannel and also SSHCommandClientEndpoint
>> in order to add extReceived.
>>
>
> An interesting question might be ... what do you want to happen to such
> data?  Do you want it mixed in with the stdout stream?
>
> For an IProtocol-based API, there aren't a lot of other options.  Maybe it
> would be useful to have a similar API that works in terms of
> IProcessProtocol instead of IProtocol?
>
> There is a ProcessEndpoint that takes a flag that controls what it does
> with stderr - currently supporting only two options, log it or drop it.
>
> What did you hook extReceived up to in your subclass?
>
> Jean-Paul
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20190406/c0f13b65/attachment-0002.html>


More information about the Twisted-Python mailing list