Download file from mainframe with FTP using HTML application

This is a HTML application that uses VBScript and the Windows DOS ftp command to download a file from the mainframe. Very handy for files that you have to download on a daily basis. You can customize the code (it is all in text) and download multiple files or change it to upload. Although I use it to download files from the mainframe you can use it for any FTP server.

What you need to do:
- Cut and save the code below and save it on your desktop.Give the file a .HTA file extension.
- Edit the code with notepad and change the DNS server addresses for your FTP servers.

To execute simple double click on the .HTA file. This will open with Internet Exploder (sorry Explorer). You can then supply your mainframe z/OS user id and password. Specify your file name in the box(without quotes) and click download. The file will be downloaded to your desktop.

<head>

<title>Mainframe Transfer FTP</title>

<HTA:APPLICATION 

     APPLICATIONNAME="MF FTP xfr"

     SCROLL="yes"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

</head>



<script language="VBScript">

Sub TestSub



Dim FSO, WS, ftpServer, username, password, ftpFile1,ftpFile2, putType, NewFile, Target

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set WS = CreateObject("WScript.Shell")

    ftpServer = Environment.value

    username = MFUser.value

    password = MFPass.value

    ftpFile1  = "'" & MFName1.value & "'"

    putType = "asci"

    Target = "C:\TEMP_FTP.txt"





If (FSO.FileExists(Target)) Then

   FSO.DeleteFile(Target)

   Set NewFile = FSO.OpenTextFile(Target, 2, "True")

Else

   Set NewFile = FSO.OpenTextFile(Target, 2, "True")

End If



NewFile.WriteLine "open " & ftpServer

NewFile.WriteLine username

NewFile.WriteLine password

NewFile.WriteLine putType

NewFile.WriteLine "get " & ftpFile1 & " FILE.TXT"

NewFile.WriteLine "close"

NewFile.WriteLine "bye"

NewFile.Close()



WS.Run "cmd /k ftp -s:" & Target,1,true



FSO.DeleteFile(Target)



    End Sub

</script>



<body>



<p>

<table>

<tr><td>Environment:</td><td><select size="1" name="Environment">

    <option selected value="unit.somewhere.com">Unit</option>

    <option value="it.somewhere.com">Integration</option>

    <option value="uat.somewhere.com">User Acceptance</option>

    <option value="prod.somewhere.com">Production</option>

</select></td></tr>

<tr><td>Mainframe User-Id:</td><td><input type="text" name="MFUser" size="8"></td></tr>

<tr><td>Mainframe Password:</td><td><input type="password" name="MFPass" size="8"></td></tr>

<tr><td>Mainframe Dataset:</td><td><input type="text" name="MFName1" size="50">File</td></tr>

</table></p>

<input type="button" value="Download from Mainframe" name="run_button"  onClick="TestSub"><p> 



</body>
Read more >>

Attachmate Extra Macro to transfer a PDS member to Microsoft Word.

If you are in editing, browsing or viewing a file in ISPF you can transfer the contents of the member to Windows with an Attachmate Extra macro.

'--------------------------------------------------------------------------------
' Macro:        winwordtrans.EBM
'
' Description:  This macro retrieves a filename from the edit / browse screen
'               and then transfers the file to the PC. After the transfer Microsoft Word
'               is opened with the transfered file.
'
Global g_HostSettleTime%

Sub Main()

'--------------------------------------------------------------------------------
' Get the main system object
 Dim Sessions As Object
 Dim System As Object
 Set System = CreateObject("EXTRA.System") ' Gets the system object
 If (System is Nothing) Then
  Msgbox "Could not create the EXTRA System object.  Stopping macro playback."
  STOP
 End If
 Set Sessions = System.Sessions

 If (Sessions is Nothing) Then
  Msgbox "Could not create the Sessions collection object.  Stopping macro playback."
  STOP
 End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
 g_HostSettleTime = 1500  ' milliseconds

 OldSystemTimeout& = System.TimeoutValue
 If (g_HostSettleTime > OldSystemTimeout) Then
  System.TimeoutValue = g_HostSettleTime
 End If

' Get the necessary Session Object
 Dim Sess0 As Object
 Set Sess0 = System.ActiveSession
 If (Sess0 is Nothing) Then
  Msgbox "Could not create the Session object.  Stopping macro playback."
  STOP
 End If
 If Not Sess0.Visible Then Sess0.Visible = TRUE
' Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
 
' This section will check if the screen is locked and ask for a password

        szString = Sess0.Screen.GetString(8,26,15)
        if (szString = "TERMINAL LOCKED") Then
            Dim szPassword
            szPassword=PasswordBox("Enter your TPX password:","Your terminal is locked")
            Sess0.Screen.Sendkeys("<Home>"   szPassword   "<Enter>") 
            Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        End If

        Dim MyArea As Object, MyArea2 As Object

' Check if the USER made a selection
        szString = Sess0.Screen.Selection
        szString = Trim(szString)
        If (szString <> "") Then
            GoTo Transfer:
        End If
        
        Sess0.Screen.MoveTo 1, 1
        Set MyArea = Sess0.Screen.Search("Command ===>")
        If (MyArea.Top = -1) Then
            msgbox("Could not find Command ===>")
            exit sub
        End If

        Sess0.Screen.MoveTo MyArea.Bottom - 1, MyArea.Left
        
        szString = Sess0.Screen.GetString(Sess0.Screen.Row,Sess0.Screen.Col,10)
        szString = Trim(szString)
       
        Select Case szString
        Case "SDSF BROWS"
            msgbox("This script does not support SDSF BROWSE, yet.")
            exit sub
        Case "SDSF EDIT"
            msgbox("This script does not support SDSF EDIT, yet.")
            exit sub
        Case "BROWSE"
            spos = 10
        Case "EDIT"
            spos = 11
        Case "VIEW"
            spos = 11
        Case Else
            leftString = Left(szString,4)
            If (leftString = "EDIT") Then
                spos = 09
            Else
                msgbox("This script does not support this screen.")
                exit sub
            End If
        End Select

        Sess0.Screen.MoveTo Sess0.Screen.Row, Sess0.Screen.Col   spos
        Set MyArea = Sess0.Screen.Search(" ",Sess0.Screen.Row,Sess0.Screen.Col)
        If (MyArea.Top = -1) Then
            msgbox("Could not find the end of the filename")
            exit sub
        End If

        szString = Sess0.Screen.GetString(Sess0.Screen.Row,Sess0.Screen.Col,MyArea.Left - Sess0.Screen.Col)
        szString = Trim(szString)

        pcfString = "c:\text.txt"
                
Transfer:
 Sess0.Screen.Sendkeys("<Home><EraseEOF>tsocmd<Enter>") 
 Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
 
 Sess0.FileTransferScheme = "Text Default" 
 Sess0.FileTransferScheme = "C:\Program Files\E!PC\schemes\Text Default.eis" 
 Sess0.FileTransferHostOS = 1  
 Recv = Sess0.ReceiveFile(pcfString,"'"   szString   "'")
        If Recv Then 
            hWndCalc% = Shell("C:\Program Files\Microsoft Office 2003\OFFICE11\WINWORD.EXE "   pcfString, 1)
        Else 
            MsgBox ("Transfer failure. Check that you don't have "   pcfString   " open in another application. If that is not the case close and reopen extra")
        End If

 Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
 Sess0.Screen.Sendkeys("end<Enter>") 

 System.TimeoutValue = OldSystemTimeout
End Sub
Read more >>

Executing JES operator commands from inside REXX.

This particular example takes the job number as input parameter and then issues the cancel command (C=J) to remove the job from JES.

/*REXX*/                                           
/*    */                                           
ARG JOBNUM                                         
IF JOBNUM = '' THEN RETURN                         
ADDRESS ISPEXEC                                    
                                                   
SIGNAL ON NOVALUE                                  
ADDRESS TSO                                        
                                                   
  'ALLOC FI(INTRDR) WRITER(INTRDR) SYSOUT(Y) REUSE'
  LIST.1 = '/*$TJ' || JOBNUM || ',C=J'             
  LIST.0 = 1                                       
  'EXECIO * DISKW INTRDR (FINIS STEM LIST.'        
  'FREE FI(INTRDR)'                                
RETURN                                             

Other examples:

Purge Job output: LIST.1 = '/*$PJ' || JOBNUM || ',PURGE'
Put Job on suspend: LIST.1 = '/*$TJ' || JOBNUM || ',C=S'
Change Job priority to 6: LIST.1 = '/*$TJ' || JOBNUM || ',P=6'

The example above is using the TSO address space to get things accomplished, but you can also use the MVS address space. The example below will cancel a userid from JES.

/* REXX */                                               
ARG ID
ADDRESS TSO 'ALLOCATE F(SUIRDR) SYSOUT(A) WRITER(INTRDR)'
ADDRESS MVS NEWSTACK                                     
QUEUE LEFT("/*$VS,'C U="ID"'",80)                        
QUEUE LEFT("XX  ",80)                                    
QUEUE ''                                                 
ADDRESS MVS 'EXECIO * DISKW SUIRDR (FINIS'               
ADDRESS MVS 'DELSTACK'                                   
ADDRESS TSO 'FREE F(SUIRDR)' 

Notes:
  • The security at your installation is going to determine if you would be able to execute these commands.


Reference:

 
Read more >>

Connect to FTP server with JCL

Connecting to a remote server with JCL involves executing the program FTP and passing regular FTP commands in the INPUT dd statement. Output from FTP will be printed in the OUTPUT dd statement.

//USERID1 JOB (X9999),'FTP',               
//         CLASS=U,MSGCLASS=X     
//*                                              
//P001     EXEC PGM=FTP,PARM='(EXIT',REGION=2048K           
//INPUT    DD *                                  
192.168.1.150
remoteid                                       
remotepasswd
asci                                             
CD x-drive                                       
PUT 'SYS1.SOME.FILE.ON.MAINF'                    
QUIT                                             
//OUTPUT   DD SYSOUT=*                           
//SYSPRINT DD SYSOUT=*                           

The FTP commands available to you will depend on the remote server's abilities. There are a lot more commands available in the z/OS FTP server than typical Linux or Windows FTP server.

Common FTP Commands


? to request help or information about the FTP commands
ascii to set the mode of file transfer to ASCII
(this is the default and transmits seven bits per character)
binary to set the mode of file transfer to binary
(the binary mode transmits all eight bits per byte and thus provides less chance of a transmission error and must be used to transmit files other than ASCII files)
bye to exit the FTP environment (same as quit)
cd to change directory on the remote machine
close to terminate a connection with another computer
  close brubeck closes the current FTP connection with brubeck,
  but still leaves you within the FTP environment.
delete to delete (remove) a file in the current remote directory (same as rm in UNIX)
get to copy one file from the remote machine to the local machine
  get ABC DEF copies file ABC in the current remote directory to (or on top of) a file named DEF in your current local directory.
  get ABC copies file ABC in the current remote directory to (or on top of) a file with the same name, ABC, in your current local directory.
help to request a list of all available FTP commands
lcd to change directory on your local machine (same as UNIX cd)
ls to list the names of the files in the current remote directory
mkdir to make a new directory within the current remote directory
mget to copy multiple files from the remote machine to the local machine;
  you are prompted for a y/n answer before transferring each file
  mget * copies all the files in the current remote directory to your current local directory, using the same filenames. Notice the use of the wild card character, *.
mput to copy multiple files from the local machine to the remote machine;
  you are prompted for a y/n answer before transferring each file
open to open a connection with another computer
  open brubeck opens a new FTP connection with brubeck;
  you must enter a username and password for a brubeck account
      (unless it is to be an anonymous connection).
put to copy one file from the local machine to the remote machine
pwd to find out the pathname of the current directory on the remote machine
quit to exit the FTP environment (same as bye)
rmdir to to remove (delete) a directory in the current remote directory

There is a nice cheat sheet PDF available from IBM that contains a short list of TCP/IP related commands which you can download here. A more complete list of commands are available here.

Notes: 
  • If you transferring files to the mainframe and you are dealing with a large file, best practice would be to preallocate the file in ISPF before transmitting.
  • There is usually a FTP server running per LPAR (Logical Partition) and you can use FTP to transfer files between LPARs.
Read more >>

Introduction

z/OS is a 64-bit operating system for mainframe computers, created by IBM. It is the successor to OS/390, which in turn followed MVS and combined a number of formerly separate, related products. z/OS offers the attributes of modern operating systems but also retains much of the functionality originating in the 1960s and each subsequent decade that is still found in daily use.

This is my daily sandbox where I play with IMS, CICS, REXX, CLIST, ISPF, TSO/E, JCL, CA7, etc.

Like Linux, z/OS has a monolithic kernel. A monolithic kernel is a kernel architecture where the entire operating system is working in the kernel space and alone as supervisor mode. This makes for a fast, secure and efficient OS. There are three types of kernel architectures:
  • Monolithic (eg. Linux and z/OS)
  • Mircrokernel (eg. Windows XP, Vista and 7)
  • Hybridkernel (eg. Mac OS X)
photo of different kernel designs
Read more >>