1

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

LonelySoul
  • 1,212
  • 5
  • 18
  • 45

2 Answers2

0

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.

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
0

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).

EventHorizon
  • 2,916
  • 22
  • 30
  • Hi Dag, Yeah the file format is EBCDIC and not ASCII. And the required fromat is CSV or EXCEL. Do I need to use Encoding while parsing. Not sure how to perform while writing. – LonelySoul May 24 '13 at 20:48
  • CSV files should be retrieved as text (using retrlines), Excel (xls) as binary and Excel (xlsx) as text. Why are you trying to download the file as binary in the second example, when the first example using retrlines worked? – EventHorizon May 24 '13 at 20:58
  • Thanks Dag. Tried that and the code which I used was "ftp.retrlines("RETR File_Name",open('ww.txt','wb').write)" but it gives me following error. "error_reply: 200 Representation type is Ascii NonPrint" – LonelySoul May 24 '13 at 21:05
  • This might be a bug in ftplib. Can you enable debugging in ftplib (set_debuglevel 1 or 2) and attach the output to your question? Remember to remove any login details from the log before posting. – EventHorizon May 24 '13 at 21:22
  • Thanks Dag. Something worked here. I am assuming the name of output file which I gave was misspeled. Thanks Again. – LonelySoul May 24 '13 at 21:31