Simple FTP Client

Daniel Dittmar daniel at dittmar.net
Sat Feb 1 20:52:28 EST 2003


Metnetsky wrote:
> I'm trying to write a very small script that will connect to a host and 
> download a file (much more to come in the future).  The following is what 
> I've assembled from the ftplib manual.  
> 
>         from ftplib import FTP
> 
>         ftp = FTP('ftp.thepaperclipse.com')
>         ftp.login("drgoslee", "patribus")
>         ftp.retrbinary('RETR ./httpdocs/dbbackups/PaperClipse_sql.tar.gz');
>         ftp.quit()
> 
> 
> Naturally however, I am getting an error.
> 
>         ftp.retrbinary('RETR/usr/local/psa/home/vhosts/thepaperclipse.com/\
>         httpdocs/dbbackups/PaperClipse_sql.tar.gz');
>         
>         TypeError: retrbinary() takes at least 3 arguments (2 given)
> 
> It makes sense, but I don't know how to correct it.  What do I need to set 
> the other parameter(s) to?  Any suggestions would be greatly appreciated.

retrbinary(command, callback[, maxblocksize[, rest]])
     Retrieve a file in binary transfer mode. command should be an 
appropriate "RETR" command: 'RETR filename'. *The callback function is 
called for each block of data received, with a single string argument 
giving the data block.*

One good kind of callback is the write method of a stream:
stream = open ('PaperClipse_sql.tar.gz', 'wb')
ftp.retrbinary ('RETR ....', stream.write)

Daniel






More information about the Python-list mailing list