| Front Page | News Headlines | Technical Headlines | Planning Features | Advanced Search |
Nobix Sponsor Message

     

Automated file transfers

By Shawn M. Gordon

There was some recent traffic on the 3000 Internet mailing list where people were asking about how to programmatically deal with file transfers through terminal emulators such as MiniSoft/92 and Reflection. About eight years ago I had the same need. I wanted to be able to see whether it was a Windows or DOS PC running MiniSoft or Reflection. At the time MiniSoft didn’t do the Mac, but Reflection did, so I would auto-sense that as well. The final step was to make sure that if someone tried to do this on a dumb terminal by mistake, that the terminal didn’t lock up, so I put some code in there to handle that as well.

First let’s start with the auto-sensing portion of the code. We have some things to set up first. I tried to keep Figure 1 below concise, so you can decide how to prompt for the PC file name and the HP file name. I’ve prompted for the PC file name, then stripped all segments that aren’t the file name using UNSTRING, then put it into a consistent 3000 group to control it further.

Figure 1


  01 STDIN              PIC S9(4)  COMP VALUE 0.
  01 TIMEOUT            PIC S9(4)  COMP VALUE 7.
  01 TERM-ID            PIC X(09)  VALUE SPACES.
  01 FILE-TYPE          PIC X      VALUE SPACES.

* First FOPEN the terminal so that we can enable FCONTROL for a
* timeout in later calls.

      CALL INTRINSIC "FOPEN" USING \\, %45 GIVING STDIN.
      CALL INTRINSIC "FCONTROL" USING STDIN, 4, TIMEOUT.
* Issue the escape sequence to request the terminal ID from the
* termulator.  %33 is the octal value for the escape key.

      DISPLAY %33 '*s12347^'.
      ACCEPT TERM-ID FREE
             ON INPUT ERROR
          DISPLAY 'You are not using a PC'
          STOP RUN.

* Here is where we tell if it's a MAC or not, we do this
* specifically because the binary file transfer on a mac is
* different than for the PC.
      IF(TERM-ID(1:1) = 'M') AND (TERM-ID(1:4) <> 'MS92')
         MOVE 'WRQ'               TO TERM-ID
         DISPLAY '(A)scii, (B)inary or (M)acBinary? '
                 NO ADVANCING
      ELSE
         DISPLAY '(A)scii or (B)inary? ' NO ADVANCING.

     ACCEPT
FILE-TYPE.

      IF TERM-ID(1:3) = 'WRQ'
         PERFORM C1000-REFLECT   THRU C1000-EXIT.
      IF TERM-ID = 'MS92 BEST'
         PERFORM C2000-MS92      THRU C2000-EXIT.

      STOP RUN.
      


Another thing to consider is whether you want to make sure you aren’t overwriting another file. I like to use a call to FLABELINFO to see if the file is there, if the call fails, then there is no conflicting file. You need to loop on the file name prompt to make sure the users can override their choice. Of course if you are transferring from the 3000 to the PC, then there really isn’t anything you can do with this process.
What I have illustrated here is how you can write a program that can auto-sense various things about the terminal emulator you are using or find out if it is a dumb terminal. With this framework you can create a relatively secure environment for uploading or downloading files without giving the users full access to the file transfer protocols built into your emulator.

The trick after this point is to be able to start up the emulator file transfer program. There are sample applications that come with the various emulators that will describe how to do this. I recommend that you follow them exactly. In the case of MiniSoft, the sample shows how to do it using the CREATEPROCESS and ACTIVATE intrinsics. I’ve tried doing it my own way, and it just didn’t work. In the case of Reflection they show how to do it with the CREATE intrinsic.

What actually happens is that one of the escape sequences you issue will return the fully qualified name of the file transfer program that is configured in the emulator. If this file doesn’t exist, then the whole process will fail, so it does rely on having everything set up to work. Once the program name is returned, you have to spawn it as a child process, hence the calls to CREATE and CREATEPROCESS. Essentially you pass the scripting language directive to the emulator via an escape sequence and away you go. It’s a bit on the confusing side when you first start out, but it really does work pretty darn well.

I’m still planning on making that trip to Sendmail/iX and showing off some utilities, but it looks as if it’s going to take more planning. Stay tuned until next month.

Shawn Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.

 


Copyright The 3000 NewsWire. All rights reserved.