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

2019-04-05 Thread Jean-Paul Calderone
On Fri, Apr 5, 2019 at 2:08 PM Sereysethy TOUCH 
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@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


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

2019-04-05 Thread Sereysethy TOUCH
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.

Sethy

On Fri, Apr 5, 2019 at 6:35 PM Sean DiZazzo  wrote:

> It looks like extReceived() is a method of SSHSession.Channel.SSHChannel
> .
> You can access it through the protocol's transport.
>
> self.transport.conn.channels[0].extReceived()
>
> ~Sean
>
> On Fri, Apr 5, 2019 at 6:27 AM Sereysethy TOUCH <
> touch.sereyse...@gmail.com> wrote:
>
>> Hello,
>>
>> I am implementing a program using SSHCommandClientEndpoint, the program
>> works fine (dataReceived got calls) but when the server send an error
>> message (stderr..), the function extReceived in my protocol never gets
>> called, instead it only calls the one in the SSHChannel as I can see in the
>> log (got extended data 1 b': No such file or directory\n'). How to override
>> that? Or how to connect it to my protocol?
>>
>> I adapted the program found on Twisted website.
>>
>> Thanks,
>> Sethy
>>
>> from twisted.conch.endpoints import SSHCommandClientEndpoint
>> from twisted.internet.protocol import Factory, Protocol
>> from twisted.python import log
>> import sys
>> from twisted.internet.defer import Deferred
>>
>> class NoiseProtocol(Protocol):
>> def connectionMade(self):
>> print("connectionMade")
>> self.finished = Deferred()
>> self.strings = ["bif", "pow", "zot"]
>> self.sendNoise()
>>
>> def sendNoise(self):
>> if self.strings:
>> self.transport.write(self.strings.pop(0) + "\n")
>> else:
>> self.transport.loseConnection()
>>
>>
>> def dataReceived(self, data):
>> print("Server says:", data)
>> self.sendNoise()
>>
>> def extReceived(self, dataType, data):
>> print("extReceived")
>>
>> def connectionLost(self, reason):
>> self.finished.callback(None)
>>
>> command = b"cat unknownfile"
>>
>> username = b""
>> password = b""
>> host = b"server"
>> port = 22
>>
>> endpoint = SSHCommandClientEndpoint.newConnection(
>> reactor, command, username, host, port,
>> password=password, agentEndpoint=None)
>>
>> factory = Factory()
>> factory.protocol = NoiseProtocol
>>
>> d = endpoint.connect(factory)
>> d.addCallback(lambda proto: proto.finished)
>> log.startLogging(sys.stdout, setStdout=0)
>> reactor.run()
>> ___
>> Twisted-Python mailing list
>> Twisted-Python@twistedmatrix.com
>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>>
> ___
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


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

2019-04-05 Thread Sean DiZazzo
It looks like extReceived() is a method of SSHSession.Channel.SSHChannel
.
You can access it through the protocol's transport.

self.transport.conn.channels[0].extReceived()

~Sean

On Fri, Apr 5, 2019 at 6:27 AM Sereysethy TOUCH 
wrote:

> Hello,
>
> I am implementing a program using SSHCommandClientEndpoint, the program
> works fine (dataReceived got calls) but when the server send an error
> message (stderr..), the function extReceived in my protocol never gets
> called, instead it only calls the one in the SSHChannel as I can see in the
> log (got extended data 1 b': No such file or directory\n'). How to override
> that? Or how to connect it to my protocol?
>
> I adapted the program found on Twisted website.
>
> Thanks,
> Sethy
>
> from twisted.conch.endpoints import SSHCommandClientEndpoint
> from twisted.internet.protocol import Factory, Protocol
> from twisted.python import log
> import sys
> from twisted.internet.defer import Deferred
>
> class NoiseProtocol(Protocol):
> def connectionMade(self):
> print("connectionMade")
> self.finished = Deferred()
> self.strings = ["bif", "pow", "zot"]
> self.sendNoise()
>
> def sendNoise(self):
> if self.strings:
> self.transport.write(self.strings.pop(0) + "\n")
> else:
> self.transport.loseConnection()
>
>
> def dataReceived(self, data):
> print("Server says:", data)
> self.sendNoise()
>
> def extReceived(self, dataType, data):
> print("extReceived")
>
> def connectionLost(self, reason):
> self.finished.callback(None)
>
> command = b"cat unknownfile"
>
> username = b""
> password = b""
> host = b"server"
> port = 22
>
> endpoint = SSHCommandClientEndpoint.newConnection(
> reactor, command, username, host, port,
> password=password, agentEndpoint=None)
>
> factory = Factory()
> factory.protocol = NoiseProtocol
>
> d = endpoint.connect(factory)
> d.addCallback(lambda proto: proto.finished)
> log.startLogging(sys.stdout, setStdout=0)
> reactor.run()
> ___
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


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

2019-04-05 Thread Sereysethy TOUCH
Hello,

I am implementing a program using SSHCommandClientEndpoint, the program
works fine (dataReceived got calls) but when the server send an error
message (stderr..), the function extReceived in my protocol never gets
called, instead it only calls the one in the SSHChannel as I can see in the
log (got extended data 1 b': No such file or directory\n'). How to override
that? Or how to connect it to my protocol?

I adapted the program found on Twisted website.

Thanks,
Sethy

from twisted.conch.endpoints import SSHCommandClientEndpoint
from twisted.internet.protocol import Factory, Protocol
from twisted.python import log
import sys
from twisted.internet.defer import Deferred

class NoiseProtocol(Protocol):
def connectionMade(self):
print("connectionMade")
self.finished = Deferred()
self.strings = ["bif", "pow", "zot"]
self.sendNoise()

def sendNoise(self):
if self.strings:
self.transport.write(self.strings.pop(0) + "\n")
else:
self.transport.loseConnection()


def dataReceived(self, data):
print("Server says:", data)
self.sendNoise()

def extReceived(self, dataType, data):
print("extReceived")

def connectionLost(self, reason):
self.finished.callback(None)

command = b"cat unknownfile"

username = b""
password = b""
host = b"server"
port = 22

endpoint = SSHCommandClientEndpoint.newConnection(
reactor, command, username, host, port,
password=password, agentEndpoint=None)

factory = Factory()
factory.protocol = NoiseProtocol

d = endpoint.connect(factory)
d.addCallback(lambda proto: proto.finished)
log.startLogging(sys.stdout, setStdout=0)
reactor.run()
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python