[Twisted-Python] how to get extReceived call from SSHCommandClientEndpoint
Sereysethy TOUCH
touch.sereysethy at gmail.com
Fri Apr 5 07:26:40 MDT 2019
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"XXXX"
password = b"XXXX"
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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20190405/4904a527/attachment.html>
More information about the Twisted-Python
mailing list