[Tutor] FTP retrieve

Ewald Ertl ewald.ertl at hartter.com
Tue Mar 15 15:48:43 CET 2005


Looking up the ftplib-Module on my Solaris-Box

>>> print sys.version
2.3.3 (#1, Mar 10 2004, 06:25:19) 
[GCC 3.3.2]

I get the following doc for retrlines of the FTP-class: 

>>> print myFTP.retrlines.__doc__
Retrieve data in line mode.
        The argument is a RETR or LIST command.
        The callback function (2nd argument) is called for each line,
        with trailing CRLF stripped.  This creates a new port for you.
        print_line() is the default callback.

Here is stated, that CRLF is stripped for each line. 

I've done something similar and opended the targetfile in "binary"-mode.
'wb' instead of 'w', so that there will be no conversion of data during the 

The data is retrieved with the following command: 

myFTP.retrbinary( "RETR " + dat, open( dat, "wb" ).write )


on Tue, 15 Mar 2005 15:30:39 +0100 (CET)  Øyvind <python at kapitalisten.no> wrote :

Øyvind > I have opened an FTP connection, and use the following to download a logfile:
Øyvind > 
Øyvind > f = open('c:///web.log','w')
Øyvind > ftp.retrlines('RETR ex050202.log', f.write)
Øyvind > 
Øyvind > I have also tried with f.writelines.
Øyvind > 
Øyvind > It works, but not as well as I would like. All the \n's are removed. How
Øyvind > can I download an exact copy, so that each line actually ends up being on
Øyvind > a separate line?
Øyvind > 
Øyvind > Thanks in advance...
Øyvind > 
Øyvind > 
Øyvind > 

------------------- end ----------------------

Ing. Ewald Ertl         HartterGruppe                   Phone : +43-3352-33085-558
trinomic Projektmanagement & Informationstechnik GmbH   Fax   : +43-3352-33085-600
Wiener Straße 41                                        mailto:ewald.ertl at trinomic.com
A-7400 Oberwart         http://www.trinomic.com         mailto:ewald.ertl at hartter.com

More information about the Tutor mailing list