[Twisted-Python] Using telnet or linereceiver protocol over ssh
![](https://secure.gravatar.com/avatar/af6977727f08b19d0701465099e54aac.jpg?s=120&d=mm&r=g)
Hello, I implemented a twisted ssh server using SSHFactory and successfully registered the sftp factory. 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? Sincerely, Fabian
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Dec 30, 2012, at 5:09 AM, Fabian Sturm <f@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 :).
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
![](https://secure.gravatar.com/avatar/af6977727f08b19d0701465099e54aac.jpg?s=120&d=mm&r=g)
Hi Glyph Am Montag, den 31.12.2012, 00:54 -0800 schrieb Glyph:
Have you looked at HistoricRecvLine <https://twistedmatrix.com/documents/current/api/twisted.conch.recvline.HistoricRecvLine.html>?
No I didn't find that! This is exaclty what I was looking for :-) I knew there had to be something better then writing this myself. I just had some trouble wiring it up, but it now finally works. For reference, what I did was to add this code to the openSSH method: def openShell(self, protocol): serverProtocol = ServerProtocol(MyRecvLine, self) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol)) And MyRecvLine is a subclass of HistoricRecvLine.
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 :).
Yeah definitively, documentation is sorely needed. For this I already bought the upcoming Twisted book. I hope that this will give me some more insight why I have to do some of the things the way they are. Unfortunately I am not sure if I am the right one for documentation since I still struggle with some of the concepts. But I would like to publish this combined sftp and command server as a reference. Sincerely, Fabian
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Jan 5, 2013, at 12:22 PM, Fabian Sturm <f@rtfs.org> wrote:
In a way, it is best to work on documentation when you don't yet fully understand, because if you fully understand you yourself don't need the documentation any more :). Obviously you don't want to write documentation that is incorrect or doesn't make sense, but the code-review process should prevent that from being published. Plus, if you are going to work on documenting something, you can always ask for help either on this mailing list, or on the IRC channel (#twisted or #twisted-dev on Freenode depending on whether your questions are about help with Twisted or help with contributing to Twisted itself). Glad I could point you in the right direction, and hope to hear more from you in the future, -glyph
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 02:23 am, glyph@twistedmatrix.com wrote:
As I may have mentioned before, I strongly disagree with this. It is much easier to (*correctly*) explain something you already understand, all other things being equal. The factor that seems to lead people to suggest that people who don't understand a thing write documentation for that thing is that once you understand it, you don't *want* the documentation *for yourself* anymore, which removes one possible motivation for creating it. But no matter how much we might want to exploit this motivation in people, it doesn't mean that the result will be good documentation. Jean-Paul
![](https://secure.gravatar.com/avatar/3a7e70f3ef2ad1539da42afc85c8d09d.jpg?s=120&d=mm&r=g)
On Sun, Jan 6, 2013 at 9:57 PM, <exarkun@twistedmatrix.com> wrote:
I agree with Jean-Paul. Writing documentation in ignorance (no offense intended to any party) is not a good way to write good documentation. I think we've seen a number of attempts at this that have resulted in pretty shoddy documentation. I do think, however, that *right after you learn* something you are in a good position to benefit the documentation of the project. The argument has also been made (not in this thread; I mean in general) that the process of learning something allows one to structure documentation about it in a way that applies well to another person learning something, but I think that concept has flaws as well. I think that a common result of such attempts is that someone will hit a common blocker in understanding their subject and then go off on a number of misguided tangents, and then when they finally come to understand the subject their sudden insight becomes associated in their mind with the resolution of the misguided attempts. But that's all just conjecture and isn't really core to my point. I think despite all these problems with writing as one learns, it's valuable to make an attempt at writing some documentation as one learns something, as long as there is a sincere modesty on one's part and a willingness to let their documentation be seriously overhauled or at least critiqued by the real experts on the subject (assuming those experts can muster the time to do the critiquing or overhauling). -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Jan 6, 2013, at 8:44 PM, Christopher Armstrong <radix@twistedmatrix.com> wrote:
I think I agree with all of that, Chris, although obviously my opinions differ from Jean-Paul's on this topic :). To be fair I believe that it's not really feasible for someone new to the topic to write anything useful entirely, or even mostly, by themselves. But if they write something basically sensible but with errors, it's easier for the experts to correct those flaws than to write something original. (Assuming, of course, that the author has put enough effort into their writing that it basically hangs together and makes sense, even if it's not entirely correct or perfectly structured.) The value of just prompting the experts to do something cannot be underestimated :). -glyph
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 05:47 am, glyph@twistedmatrix.com wrote:
"Easier" is in the eye of the beholder.
The value of just prompting the experts to do something cannot be underestimated :).
Yes, so become a 2013 Twisted sponsor today! http://twistedmatrix.com/trac/wiki/TwistedSponsors Jean-Paul
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Dec 30, 2012, at 5:09 AM, Fabian Sturm <f@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 :).
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
![](https://secure.gravatar.com/avatar/af6977727f08b19d0701465099e54aac.jpg?s=120&d=mm&r=g)
Hi Glyph Am Montag, den 31.12.2012, 00:54 -0800 schrieb Glyph:
Have you looked at HistoricRecvLine <https://twistedmatrix.com/documents/current/api/twisted.conch.recvline.HistoricRecvLine.html>?
No I didn't find that! This is exaclty what I was looking for :-) I knew there had to be something better then writing this myself. I just had some trouble wiring it up, but it now finally works. For reference, what I did was to add this code to the openSSH method: def openShell(self, protocol): serverProtocol = ServerProtocol(MyRecvLine, self) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol)) And MyRecvLine is a subclass of HistoricRecvLine.
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 :).
Yeah definitively, documentation is sorely needed. For this I already bought the upcoming Twisted book. I hope that this will give me some more insight why I have to do some of the things the way they are. Unfortunately I am not sure if I am the right one for documentation since I still struggle with some of the concepts. But I would like to publish this combined sftp and command server as a reference. Sincerely, Fabian
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Jan 5, 2013, at 12:22 PM, Fabian Sturm <f@rtfs.org> wrote:
In a way, it is best to work on documentation when you don't yet fully understand, because if you fully understand you yourself don't need the documentation any more :). Obviously you don't want to write documentation that is incorrect or doesn't make sense, but the code-review process should prevent that from being published. Plus, if you are going to work on documenting something, you can always ask for help either on this mailing list, or on the IRC channel (#twisted or #twisted-dev on Freenode depending on whether your questions are about help with Twisted or help with contributing to Twisted itself). Glad I could point you in the right direction, and hope to hear more from you in the future, -glyph
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 02:23 am, glyph@twistedmatrix.com wrote:
As I may have mentioned before, I strongly disagree with this. It is much easier to (*correctly*) explain something you already understand, all other things being equal. The factor that seems to lead people to suggest that people who don't understand a thing write documentation for that thing is that once you understand it, you don't *want* the documentation *for yourself* anymore, which removes one possible motivation for creating it. But no matter how much we might want to exploit this motivation in people, it doesn't mean that the result will be good documentation. Jean-Paul
![](https://secure.gravatar.com/avatar/3a7e70f3ef2ad1539da42afc85c8d09d.jpg?s=120&d=mm&r=g)
On Sun, Jan 6, 2013 at 9:57 PM, <exarkun@twistedmatrix.com> wrote:
I agree with Jean-Paul. Writing documentation in ignorance (no offense intended to any party) is not a good way to write good documentation. I think we've seen a number of attempts at this that have resulted in pretty shoddy documentation. I do think, however, that *right after you learn* something you are in a good position to benefit the documentation of the project. The argument has also been made (not in this thread; I mean in general) that the process of learning something allows one to structure documentation about it in a way that applies well to another person learning something, but I think that concept has flaws as well. I think that a common result of such attempts is that someone will hit a common blocker in understanding their subject and then go off on a number of misguided tangents, and then when they finally come to understand the subject their sudden insight becomes associated in their mind with the resolution of the misguided attempts. But that's all just conjecture and isn't really core to my point. I think despite all these problems with writing as one learns, it's valuable to make an attempt at writing some documentation as one learns something, as long as there is a sincere modesty on one's part and a willingness to let their documentation be seriously overhauled or at least critiqued by the real experts on the subject (assuming those experts can muster the time to do the critiquing or overhauling). -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Jan 6, 2013, at 8:44 PM, Christopher Armstrong <radix@twistedmatrix.com> wrote:
I think I agree with all of that, Chris, although obviously my opinions differ from Jean-Paul's on this topic :). To be fair I believe that it's not really feasible for someone new to the topic to write anything useful entirely, or even mostly, by themselves. But if they write something basically sensible but with errors, it's easier for the experts to correct those flaws than to write something original. (Assuming, of course, that the author has put enough effort into their writing that it basically hangs together and makes sense, even if it's not entirely correct or perfectly structured.) The value of just prompting the experts to do something cannot be underestimated :). -glyph
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 05:47 am, glyph@twistedmatrix.com wrote:
"Easier" is in the eye of the beholder.
The value of just prompting the experts to do something cannot be underestimated :).
Yes, so become a 2013 Twisted sponsor today! http://twistedmatrix.com/trac/wiki/TwistedSponsors Jean-Paul
participants (4)
-
Christopher Armstrong
-
exarkun@twistedmatrix.com
-
Fabian Sturm
-
Glyph