[Tutor] FTP from mainframe

bob gailer bgailer at gmail.com
Thu Jul 29 19:34:18 CEST 2010


On 7/29/2010 12:34 PM, Steve Bricker wrote:
> This is my first attempt to FTP a file from a mainframe.  The code:
>
> import ftplib
> session = ftplib.FTP('company.lan.com','userid','passwd')
> myfile = open('PC.filename','w')
> session.retrlines("RETR 'mainframe.filename'", myfile)
> myfile.close()
> session.quit()
>
> The resulting error is:
>
> Traceback (most recent call last):
>   File "ftp_from_mf.py", line 5, in <module>
>     session.retrlines("RETR 'mainframe.filename'", myfile)
>   File "c:\python26\lib\ftplib.py", line 428, in retrlines
>     callback(line)
> TypeError: 'file' object is not callable

According to the ftplib module documentation:

retrlines(command[, callback])
Retrieve a file or directory listing in ASCII transfer mode. command 
should be an appropriate RETR command (see retrbinary()) or a command 
such as LIST, NLST or MLSD (usually just the string 'LIST'). The 
callback function is called for each line, with the trailing CRLF 
stripped. The default callback prints the line to sys.stdout.

IOW callback must be a function. You are passing a file object. I will 
guess that you want:

def writer(line):
   myfile.write(line + '\n')

session.retrlines("RETR 'mainframe.filename'", writer)

The documentation is in error in that it does not explicitly state that 
a line is passed to the callback function as an argument. I am assuming 
that is the case.

-- 
Bob Gailer
919-636-4239
Chapel Hill NC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100729/f4521046/attachment-0001.html>


More information about the Tutor mailing list