manish reddy
manish reddy

Reputation: 19

Trying to FTP file using python script to Mainframe server, but getting special characters at mainframe dataset end

Trying to FTP file using python script to Mainframe server, but getting special characters at mainframe dataset end

from ftplib import FTP

host = "hostname"
user = "username"
password = "pass"

with FTP(host) as ftp:
    ftp.login(user = user, passwd = pass)
    print(ftp.getwelcome())

    with open('test.txt', 'rb') as f:
        ftp.storbinary('STOR ' + "'TestDataset'", f)

    ftp.quit()

This is the code which I have used to FTP a file to mainframe server, looks like encoding issue. Mainframe uses EBCDIC and python default encoding has UTF-8 or UTF-16, but not able to resolve it, please help. Thank you

This is the output which I'm able to see at mainframe end, Content of text.txt is "Hi there"

enter image description here

Upvotes: 1

Views: 1272

Answers (1)

phunsoft
phunsoft

Reputation: 2745

I don't know python, so can't tell what you need to code, but: The mainframe FTP server has a setting to tell it the "network side" code page, i.e. you server's side UTF-8 or UTF-16, and the mainframe side code page.

In an FTP session from Windows to a mainframe, I would issue

quote site sbdataconn=(IBM-037,UTF-8)

NOTE (Edit 21.08.2021) I had the code pages mixed, and have just corrected this. It is "z/OS side code page" (or z/OS file system code page) followed by "network side code page".

You might want to find out how to specify this using the python ftp interface. Note that you probably don't need the quote keyword but can start with site keyword directly.

You also need to find you what EBCDIC code page exactly is being used on the mainframe. In the US, it probably is either IBM-037 or IBM-1047. In other countries it may as well be any of the country specific EBCDIC code pages.

Upvotes: 1

Related Questions