ftplib and zipfile question
vlindberg at verio.net
Tue Mar 27 03:36:25 CEST 2001
I am writing a program to download something from an ftp site. I have
checked the ftplib documentation and I know that I need the retrbinary
command. However, the docs say:
retrbinary (command, callback[, maxblocksize[, rest]]) Retrieve a file
in binary transfer mode. command should be an appropriate "RETR"
command, i.e. 'RETR filename'. The callback function is called for each
block of data received, with a single string argument giving the data
What is the callback command? Could anyone give an example of the use
of this command to download a file and save it locally?
Further, does python have anything like the Unix pipe? The file in
question is a zip file. If possible, I would rather just pipe it
through to the zipfile module.
In short, is this possible?
import zlib, zipfile
from ftplib import FTP
ftp = FTP('mysite.com', 'anonymous', 'me at myaddress.com')
myzip = Zipfile((ftp.retrbinary('binaryfile.zip', OTHER_ARGS_HERE), 'r')
for filename in myzip.namelist:
file = open(filename, 'w')
If possible, I would like to process the file as it goes through,
without either incurring huge memory usage or having to save the file to
If I have to choose one or the other, tho, I would store the file to
More information about the Python-list