HP 3000 Manuals

Using FTP Commands in UDCs and Programs [ HP ARPA File Transfer Protocol User's Guide ] MPE/iX 5.0 Documentation


HP ARPA File Transfer Protocol User's Guide

Using FTP Commands in UDCs and Programs 

You can use FTP commands in UDCs, command files and programs to help you
perform tasks such as:

   *   Automating the connection and logon process

   *   Transferring multiple files

   *   Creating batch jobs

Using EXITONERROR 

The MPE XL FTP command  EXITONERRORallows you to turn on or off the
capability to exit an FTP session if an error occurs.  The last error and
message are saved in CI variables.  To show the errors enter the
following at the MPE XL colon prompt:

     :SHOWVAR FTP@ 

In the following example, EXITONERROR is activated.  The second GET
command generates an error because the file does not exist:

     ftp> EXITONERROR 
     ExitOnError mode on. (FTPINFO 33)
     ftp> GET filex filey 
     200 PORT command okay.
     150 Opening data connection for filey (192.50.42.32,50897) (320 bytes).
     226 Transfer complete.
     322 bytes received in 0.65 seconds: (4.25 Kbytes/second)
     ftp> GET filez 
     200 PORT command okay.
     550 filez: No such file or directory.
     Data Transfer Request Failed. (FTPERR 13)
     END OF PROGRAM
     :

     :SHOWVAR ftp@ 
     FTPLASTERR = 13
     FTPLASTREPLY = 550 filez: No such file or directory
     FTPLASTMSG = Data Transfer Request Failed.  (FTPERR 13)
     :

Transferring Multiple Files 

You can create a command file to automatically copy a group of files from
the remote system into your account as in the following example.

   1.  Create a file with the following contents:
_____________________________________________________
|                                                   |
|     parm node, user, pass                         |
|     continue                                      |
|     purge ftpcmds,temp                            |
|                                                   |
|     echo exitonerror                    >> ftpcmds|
|     echo open !node                     >> ftpcmds|
|     echo user !user !pass               >> ftpcmds|
|     echo get file1 file1                >> ftpcmds|
|     echo get file2 file2                >> ftpcmds|
|     echo get file3 file3                >> ftpcmds|
|     echo quit                           >> ftpcmds|
|                                                   |
|     run ftp.arpa.sys; stdin=ftpcmds               |
|                                                   |
|     if !FTPLASTERR <> 0 then                      |
|        showvar FTP@                               |
|     endif                                         |
|                                                   |
|     continue                                      |
|     purge ftpcmds,temp                            |
_____________________________________________________

            

   2.  From the CI, (:)  enter the following to execute the command file
       you created:

            : yourfile remotehostname  username password 

        EXITONERROR is enabled in the above example.  If there is an
       error while executing, the error will be printed on the terminal
       display.

You can create a UDC using the same set of commands above, except
changing the word  parm to a UDC name such as getfiles.  The first
statement for this UDC is:

     getfiles node, user, pass

Enter the contents of the file in your UDC file.  To execute this UDC,
you would enter:

     :getfiles  remotehostname  username  password 

Using a Jobstream 

The following example shows how to use a job file to automate the logon
procedure and retrieve a file from a remote system.  To execute a job,
enter  STREAM  jobname at the MPE XL prompt (:).
_____________________________________
|                                   |
|     !JOB FTPFILE,USERNAME.ACCT,PUB|
|     !RUN FTP.ARPA.SYS             |
|     OPEN 192.50.42.32             |
|     USER remuser rempass          |
|     PWD                           |
|     DIR *                         |
|     GET file1                     |
|     QUIT                          |
|     !EOJ                          |
_____________________________________

            

Programmatic Example 

You can use FTP commands in programs using the HPCICOMMAND intrinsic as
in the following example.  The input file containing the FTP commands,
FTPIN, is listed following the program.
__________________________________________________________________________
|                                                                        |
|     program ftp_prog (input, output);                                  |
|     Const                                                              |
|     msglevel          = 0                                              |
|     cr                = chr (13);                                      |
|     var                                                                |
|     cmdimage          : string [80];                                   |
|     cmderror          : shortint;                                      |
|     parmnum           : shortint;                                      |
|     procedure HPCICOMMAND; intrinsic                                   |
|     begin                                                              |
|     { ----------------------------------------------------------------}|
|     { Run the User-FTP program using the FTPIN input file.            }|
|     { The FTPOUT file will be created in the temporary space          }|
|     { and will contain the output of the FTP session.                 }|
|     {-----------------------------------------------------------------}|
|     cmdimage := 'RUN FTP.ARPA.SYS;STDIN=FTPIN;STDLIST=FTPOUT,NEW' + cr;|
|     HPCICOMMAND (cmdimage,cmderror,parmnum,msglevel);                  |
|     if cmderror <> 0 then                                              |
|     begin                                                              |
|     writelin ( 'CMDERROR = ', cmderror:1 );                            |
|     writelin ( 'PARMNUM = ', parmnum:1 );                              |
|     end;                                                               |
|     end.                                                               |
__________________________________________________________________________

            

The contents of  FTPIN are listed below:
_____________________________________
|                                   |
|     OPEN 192.50.42.32             |
|     USER remuser rempass          |
|     PWD                           |
|     DIR *                         |
|     GET file1                     |
|     GET file2                     |
|     GET file3                     |
|     QUIT                          |
_____________________________________

            



MPE/iX 5.0 Documentation