On Wed, Apr 10, 2013 at 12:20 PM, yuyan zhang <z858570...@gmail.com> wrote: > i use nc command > bash-3.2# nc 83.85.85.238 21 > 220 (vsFTPd 2.0.5) > get the version of the ftp > but i want to use twisted to do this,and i don't know the function > can anyone help me?
Perhaps this is what you are looking for: # getversion.py import sys from twisted.internet.protocol import ClientFactory from twisted.protocols.basic import LineReceiver class GetVersion(LineReceiver): def lineReceived(self, line): sys.stdout.write(line + '\n') # close after first line self.transport.loseConnection() class MyFactory(ClientFactory): protocol = GetVersion clientConnectionLost = lambda *a: reactor.stop() clientConnectionFailed = lambda *a: reactor.stop() if __name__ == '__main__': from twisted.internet import reactor host, port = '83.85.85.238', 21 reactor.connectTCP(host, port, MyFactory()) reactor.run() _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python