[Twisted-Python] Using telnet or linereceiver protocol over ssh

Glyph glyph at twistedmatrix.com
Mon Dec 31 03:54:33 EST 2012


On Dec 30, 2012, at 5:09 AM, Fabian Sturm <f at rtfs.org> wrote:

> Hello,

Hi Fabian,

> I implemented a twisted ssh server using SSHFactory and successfully
> registered the sftp factory.

Great, you're pretty far along then :).

> I now also wanted to add a simple telnet like protocol where I can send
> commands to the server and execute some actions based on that.
> For that I hooked the LineReceive to the openShell command. It works and
> I can ssh into the server, but I don't get the typed characters echoed
> back. This unfortunately makes it unusable.
> 
> What I could do is to implement a standard Protocol and send the
> received data back whenever I get a dataReceived call. And for a DEL
> character I would have to send a BCKSPC, BLANK, BACKSPC sequence and
> track the current line myself. This works but it sounds like too much to
> do!
> 
> Is there a better way for something like that?

Have you looked at HistoricRecvLine <https://twistedmatrix.com/documents/current/api/twisted.conch.recvline.HistoricRecvLine.html>?

It's not the easiest class to use, but it should do basically what you need, with various line-editing niceties.

This is also an area that could really benefit from some more maintenance, both in the code and the documentation; writing a command-line interface to Twisted should be a lot easier and more obvious.  So if you'd like to contribute to Twisted this is a good place to start :).

-glyph




More information about the Twisted-Python mailing list