Using an Object Instance as an FTP Callback : FTP « Network « Python






Using an Object Instance as an FTP Callback

 

class Writer:
    def __init__(self, file):
        self.f = open(file, "w")

    def __call__(self, data):
        self.f.write(data)
        self.f.write('\n')
        print data

FILENAME = "AutoIndent.py"
writer = Writer(FILENAME)

import ftplib
ftp = ftplib.FTP('127.0.0.1', 'book', 'bookpw')
ftp.retrlines("RETR %s" % FILENAME, writer)

   
  








Related examples in the same category

1.An FTP-to-FTP Transfer Program
2.Debug Output from an FTP Transfer
3.Download file from FTP server