Yes, I'm sort of a Twisted newbie, so maybe this has an obvious answer, but I'm just not seeing it.<br><br>I have a Twisted program that I need to add in the ability to make a client telnet connection to a remote server and send some commands to it and deal with the data received.
<br><br>In my main program I have this line of code:<br> reactor.connectTCP("mytelnethost", 24, Connections.TelnetConnection("myname of object",events,"command to run"))<br><br>My Connections.TelnetConnection
class looks like this:<br><br>from twisted.internet.protocol import Protocol, ReconnectingClientFactory<br>from twisted.conch.telnet import Telnet<br><br>class TelnetClient(Telnet):<br> def connectionMade(self):<br> print "connection made"
<br> self.write("\r\n")<br> <br> def write(self, data):<br> print data<br> Telnet._write(self, data+"\r\n")<br><br> def dataReceived(self, data):<br> print "received:", data
<br> if "User Name:" in data:<br> self.write("user")<br><br> if "Password:" in data:<br> self.write("password")<br> <br><br> if ">" in data:<br>
time.sleep(2)<br> self.write("connect")<br> if "Connector Name:" in data:<br> time.sleep(2)<br> self.write("another command")<br><br><br><br>class TelnetConnection(Connection, ReconnectingClientFactory):
<br> """ Telnets to host:port and executes cmd. cmd """<br> protocol = TelnetClient<br> def __init__(self, name, eventQueue, cmd=None): <br> Connection.__init__(self, name)<br>
<br> def clientConnectionFailed(self, connector, reason):<br> print 'connection failed:', reason.getErrorMessage()<br> <br><br> def clientConnectionLost(self, connector, reason):<br> print 'connection lost:',
reason.getErrorMessage()<br><br><br><br>This all works great, except that the command sequence is hard coded in the TelnetClient class. I want to be able to reference the "cmd" parameter, which could be a list of commands to iterate over,etc. But I don't see how I can access the "cmd" parameter that gets passed into the TelnetConnection class from within the TelnetClient class.
<br><br>I'm really desparate for some help, I've been racking my brain on this since yesterday morning.<br><br>Thanks,<br><br>Don<br><br>