Transferring files to an IBM mainframe using IND$FILE

In this example, an IBM 3270 session is embedded in the browser window, and HTML form elements are used to provide controls for performing IND$FILE file transfers between the desktop computer and the mainframe. A "file" type input field is used on the form; this provides both a text field and a Browse button for selecting the local file to send to the host. Because the user is not given access to any of the Reflection menus or dialog boxes in this example, the administrator may want to preconfigure all file transfer settings in the File Transfer Setup dialog box, then save those settings to a configuration file.

To use this example, you must change the hostURL parameter in the <applet> tag below to a host appropriate for your network.

<html>
<head>
<title>Example of Transferring Files to an IBM Mainframe Using IND$FILE</title>
<script language="JavaScript">
<!--
    /*
       This function handles a click in either the Send File or Receive
       File button. It first ensures that Reflection is available and
       initialized, and then it gets the values of the <form> elements into an
       array, determines the direction of the transfer, and transfers the
       specified file.
    */
    function transferFile( direction )
    {
       // Get the Reflection session applet and make sure it is initialized.
       var rw;
       if ( (rw = getRWebAPI()) == null )
       {
          alert( "Unable to find Reflection, or Reflection is not initialized." );
          return;
       }

       // Create an Array object to store the <form> values, and get
       // the values. If any of the required values could not be
       // returned, exit the function without transferring the file.
       var fields = new Array();
       if ( getFields( fields ) )
       {
          // Determine the direction of the transfer, and then issue the
          // appropriate API method, passing the four field values
          // as parameters.
          if ( direction == "send" )
             rw.indSendFile( fields[0], fields[1], fields[2], fields[3] );
          else if ( direction == "receive" )                    
             rw.indReceiveFile( fields[0], fields[1], fields[2], fields[3] );
          else
             alert( "Invalid parameter specified for transfer direction." );
        }

        // After the transfer, request the display focus for the session,
        // so the user can type in the terminal session window.
        rw.requestDisplayFocus();
    }

    /*
       This function gets a reference to the IBM 3270 applet on the
       page, and then gets a reference to the JSAPI for the session,
       and then ensures that it is initialized. The function returns
       the API reference if the session is available, or null if either
       the session or API is not available or not initialized.
    */
    function getRWebAPI()
    {
       var targetApplet = document.IBM3270;
       if ( targetApplet == null ) return null;
       var api = targetApplet.getAPI( "JSAPI", "IBM3270" );
       if ( api == null ) return null;
       if ( api.getInitialized() <= 0 ) return null;
       return api;
    }

    /*
       This function fills in the array object with the values from
       the <form> elements. The function returns true if all of the values
       are valid, or false if the data is not valid. In this example,
       both the local file and the host file are required information,
       so if either is missing, an alert message is displayed.
    */
    function getFields( fields )
    {
       var localFile, hostFile, isAscii, showStatus;
        
       if ( (localFile = document.FileTransfer.localfile.value) == "" )
       {
          alert( "You must enter a local file name." );
          return false;
       }
       if ( (hostFile = document.FileTransfer.hostfile.value) == "" )
       {
          alert( "You must enter a host file name." );
          return false;
       }

       var typeList = document.FileTransfer.FileType;
       isAscii = (typeList.options[typeList.selectedIndex].index == 0) ? true : false;

       showStatus = true; // Currently unused; can be either true or false.
                
       // Fill in the array with the valid data.
       fields[0] = localFile;
       fields[1] = hostFile;
       fields[2] = isAscii;
       fields[3] = showStatus;

       return true;
    }
//-->
</script>
</head>
<body>
<h1>Reflection for the Web -- IBM 3270</h1>
<p>
<!--
   This is the tag that launches an IBM 3270 terminal session.
   To use this example, change the hostURL parameter to one
   appropriate for your network.
-->
<applet mayscript name="IBM3270"
        codebase="./ex/"
        code="com.wrq.rweb.Launcher.class"
        width="600" height="400"
        archive="Launcher.jar">
   <param name="hostURL" value="tn3270://payroll">
   <param name="launcher.sessions" value="IBM3270">
   <param name="preloadJSAPI" value="true">
</applet>
</p>
<!--
   A series of <form> elements are created to let the user enter
   the name of the local file, the name of the host file, and
   the format for transferring the file (either ASCII or Binary).
   Two buttons trigger the file transfer. By using an INPUT type
   of "FILE", the local file name field looks like a text field,
   but also gets a Browse button for browsing for a local file.
   Note, however, that the Browse dialog box cannot be used to
   specify a file to save when receiving a file from the host.
-->
<form name="FileTransfer">
<p>Local File Name:&nbsp;<input type="file" size="40" name="localfile"></p>
<p>Host File Name:&nbsp;&nbsp;<input type="text" value="" size="40" name="hostfile"></p>
<p>File type: <select name="FileType">
<option selected>ASCII</option>
<option>Binary</option>
</select>
</p>
<p>
<input type="button" name="RecvFile" value="<< Receive File"       onClick="transferFile( 'receive' )">&nbsp;
<input type="button" name="SendFile" value="Send File >>"       onClick="transferFile( 'send' )">
</p>
</form>
</body>
</html>