ftp
Fredrik Lundh
fredrik at pythonware.com
Fri Dec 17 10:46:30 EST 2004
"hawkmoon269" <rson at new.rr.com> wrote:
> It turns out that the retrlines method strips of EOL CRLF and \n. My
> solution was to create a new method in ftplib that doesn't do this.
> I'm assuming that there is a better OOP solution to this, e.g. some
> kind of subclassing, but do not have the expertise as yet to implement
> that.
reading the documentation might help, somewhat:
retrlines( command[, callback])
Retrieve a file or directory listing in ASCII transfer mode. command should
be an appropriate "RETR" command (see retrbinary()) or a "LIST" command
(usually just the string 'LIST'). The callback function is called for each line,
with the trailing CRLF stripped.
so if you want line endings, just use a callback that adds line endings:
def mycallback(line):
print line
ftp.retrlines("RETR ...", mycallback)
or, perhaps:
file = open("output.txt", "w")
def mycallback(line):
# note: file is a global variable
file.write(line)
file.write("\n")
ftp.retrlines(...)
(since the file is opened in text mode, the write method will automatically
convert "\n" to "\r\n" on windows).
</F>
More information about the Python-list
mailing list