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

Rolando Espinoza La Fuente darkrho at gmail.com
Wed Apr 10 14:53:27 EDT 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 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

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 = '', 21
    reactor.connectTCP(host, port, MyFactory())

More information about the Twisted-Python mailing list