Yes, I'm sort of a Twisted newbie, so maybe this has an obvious answer, but I'm just not seeing it.
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.
In my main program I have this line of code:
reactor.connectTCP("mytelnethost", 24, Connections.TelnetConnection("myname of object",events,"command to run"))
class looks like this:
from twisted.internet.protocol import Protocol, ReconnectingClientFactory
from twisted.conch.telnet import Telnet
print "connection made"
def write(self, data):
def dataReceived(self, data):
print "received:", data
if "User Name:" in data:
if "Password:" in data:
if ">" in data:
if "Connector Name:" in data:
class TelnetConnection(Connection, ReconnectingClientFactory):
""" Telnets to host:port and executes cmd. cmd """
protocol = TelnetClient
def __init__(self, name, eventQueue, cmd=None):
def clientConnectionFailed(self, connector, reason):
print 'connection failed:', reason.getErrorMessage()
def clientConnectionLost(self, connector, reason):
print 'connection lost:',
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.
I'm really desparate for some help, I've been racking my brain on this since yesterday morning.