Question

I am trying to parse / download some of the files from Mainframe using ftplib but it's unsuccesful after few attempts.

My code Till now is :

import ftplib
ftp = ftplib.FTP('host','username','password')
ftp.retrlines("File To be Downloaded")

This works fine and I can see the required file.

However when I use following code.

ftp.retrbinary("RETR 'File_Name'",open('ww.txt','wb').write)

It fails with following error.

error_reply: 200 Representation type is Image

Based on reponse of Dag, I tried the following code to download file through "retrlines".

ftp.retrlines("RETR 'File_Name'",open('ww.txt','wb').write)

But it gives me following error.

error_reply: 200 Representation type is Ascii NonPrint

Was it helpful?

Solution

What is the expected result? Retrlines reads the file as text, which is correct for text files. Retrbinary retrieves the file as a binary file. This is a bad idea if you are targetting a mainframe using EBCDIC instead of ASCII, and might be the reason you get this result code (which according to FTP spec is not an error).

OTHER TIPS

Try explicitly setting "TYPE" in your Python script:

http://publib.boulder.ibm.com/infocenter/zos/v1r12/index.jsp?topic=%2Fcom.ibm.zos.r12.halu001%2Ftype.htm

I'm guessing unless you specify a type, the default is probably "ASCII". A Pop Favorite for most binary FTP transfers is "BINARY". I'm not sure what's most appropriate for your system: "IMAGE", perhaps?

Also: look at this link: Downloading text files with Python and ftplib.FTP from z/os.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top