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

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to