Simple FTP Client

Andrew Bennetts andrew-pythonlist at
Sun Feb 2 02:27:11 CET 2003

On Sat, Feb 01, 2003 at 08:09:25PM -0500, 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.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/\
>         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.

As stated at
    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. The optional maxblocksize argument
        specifies the maximum chunk size to read on the low-level socket
        object created to do the actual transfer (which will also be the
        largest size of the data blocks passed to callback). A reasonable
        default is chosen. rest means the same thing as in the transfercmd()

You need to pass a callback method, which will be called with each piece of
data as it comes in.


    f = open('downloaded.file', 'w')
    ftp.retrbinary(....,  f.write)


More information about the Python-list mailing list