[Twisted-Python] use twisted get ftp's version

Rolando Espinoza La Fuente darkrho at gmail.com
Wed Apr 10 12:53:27 MDT 2013


On Wed, Apr 10, 2013 at 12:20 PM, yuyan zhang <z858570636 at 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()




More information about the Twisted-Python mailing list