0

I am new to python, I found this thread most suited for my query. How do I connect to mainframe server using python3, i know there is ftplib to connect but I am not able to find out how I provide following info to logon: 1. region(development) 2. username, password 3. account

whenever I connect to mainframe I should enter a region name before I can be prompted to enter username and password. And then I must enter an account name.

Please let me know if further information is required. I appreciate any help that may come from anyone.

I tried to use hllapi function :

      h_func = c_int(1)
      h_text = c_wchar_p("F")
      h_len = c_int(1)
      h_ret = c_int(999)
      #Function calling
      hllapi(byref(h_func), h_text, byref(h_len), byref(h_ret))

output: 1 F 1 1 --> why am I getting return code 1? Isit because I used c_wchar_p instead of c_char_p? If I use c_char_p('F') it does not accept a charater. What could be the reason?

Jatinder
  • 51
  • 1
  • 1
  • 9
  • Region, Username, Password, Account? This doesn't look like FTP. Please tell us which Protocol you want to use and what do you mean by "connect". – Matthias Oct 05 '13 at 20:26
  • Thanks Matthias for your quick reply. I want to be able logon to Mainframe development region, which has a unique name which is required to be entered before it asks for username and password. After username password has been authenticated, it asks for account name(again a unique name) which must be entered to get to the ISPF. Thats how it goes when I use IBM personal communications. Protocol used is TCP/IP. But I have no Idea how to achieve this using Python. I want to be able to read from PS or member names from PDS or read from members from PDS. – Jatinder Oct 05 '13 at 20:37
  • http://stackoverflow.com/questions/11763405/python-ctypes-dlls-and-pcomm-emulation-how-can-i-pre-alocate-a-variable May be of some help, it is window's specific. – sean Oct 05 '13 at 23:39
  • This sounds like TN3270. – Anthony Giorgio Oct 13 '13 at 04:36

2 Answers2

1

If you're going to be using ISPF then you will probably be screen scraping. This means you will be interacting with a 3270 emulator, possibly via HLLAPI.

An alternative, which may be available to you, is to use SSH. Many mainframe systems are now accessible via this protocol. If Python supports it, and your mainframe people allow it, SSH may be easier.

cschneid
  • 10,237
  • 1
  • 28
  • 39
  • You should be able to connect to the mainframe via FTP, you need the Server-id, userid & password. You can only send / receive files with FTP though – Bruce Martin Oct 06 '13 at 00:20
  • Thanks for your replies...Is there any way I can use EHLLAPI from IBM in python. I searched all over neither I could find package downloader nor implementation in python. For now I'd be happy to find EHLLAPI download. thanks in advance... – Jatinder Oct 06 '13 at 12:54
  • For my previous question..I was able to implement FTP as follows : – Jatinder Oct 06 '13 at 13:58
  • from ftplib import FTP def main(): sys = input(str("Please enter system : ")) try: ftp = FTP(sys) except Exception as eftp: print("Unable to contact server", eftp) exit() userName = input(str("Please enter User ID : ")) passWord = input(str("Please enter password : ")) acct = input(str("Please enter account : ")) try: msg = ftp.login(userName,passWord,acct) print(msg) except Exception as e: print("Authentication Failed", e) exit() – Jatinder Oct 06 '13 at 14:00
  • pds = input(str("Please enter PDS name : ")) try: dire = ftp.cwd(pds) print(dire) print(ftp.dir()) except Exception as efile: print("invalid pds name",efile) exit CLIST = ftp.nlst() print(CLIST) for files in CLIST: lines = [] content = ftp.retrlines("RETR "+files, lines.append) pcfile = open(files+'.txt','w') for line in lines: pcfile.write(line+"\n") pcfile.close() ftp.close() – Jatinder Oct 06 '13 at 14:01
  • @Jatinder if you copy all your comments and paste them into your question, you can keep the formatting. What do you want to do once you have connected to the Mainframe? – Bill Woodger Oct 07 '13 at 16:35
  • @Bill Woodger : I want to be able to provide a GUI, using python, to : 1. FTP(PS and PDS) 2. Check spool logs 3. Check job status and provide inputs to restart or rerun 4. If possible, automate process that we carry out to resolve common abends. 5. To generate reports for jobs having time taken to execute 6. Carry out common tasks on Datasets, e.g. sort, merge, reformat, may be by sending out a jcl to JES for execution. May be what I have mentioned is very absurd but that should give you an idea what I want to achieve. – Jatinder Oct 08 '13 at 08:58
  • @Jatinder: You want to write the IBM Explorer for z/OS. – cschneid Oct 08 '13 at 11:42
  • @cschneid thanks for the spoiler :P Now I guess I want all the above information just for my knowledge. But I still want to know how to use these APIs. – Jatinder Oct 08 '13 at 13:12
0

To add on cschneid answer above, I was able to implement a solution involving screen scraping.

I was able to implement the following Python package:

https://pypi.org/project/py3270/

The emulator that I utilized can be found here:

https://sourceforge.net/projects/x3270/

Michael K
  • 17
  • 1
  • 8