This example describes Python as an FTP callback method by defining a class instance. Share to everyone for your reference. The implementation methods are as follows:
|1 2 3 4 5 6 7 8 9 10 11-12||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)|
I hope this article will help you with your Python programming.