HP 3000 Manuals

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


HP ARPA File Transfer Protocol User's Guide

Using FTP Commands in UDCs and Programs 

You can use FTP commands in User Defined Commands (UDC), 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/iX FTP command EXITONERROR allows 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/iX colon prompt: 

     :SHOWVAR FTP@

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

                                Table 4-14.   
-----------------------------------------------------------------------
|  |                                                                  |
|  | ftp> EXITONERRORExitOnError mode on.  (FTPINFO 33) ftp> GET      |
|  | filex filey200 PORT command okay.  150 Opening data connection   |
|  | for filey (123.50.42.32,50897) (320 bytes).  226 Transfer        |
|  | complete.  322 bytes received in 0.65 seconds:  (4.25            |
|  | Kbytes/second) ftp> GET filez200 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) :                                           |
|  |                                                                  |
-----------------------------------------------------------------------


NOTE FTPLASTERR indicates an error if the value is negative and a warning if the value is positive.
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: Table 4-15. ---------------------------------------------------------- | | | | parm node, user, pass continue | | | purge ftpcmnds,temp | | | | | ---------------------------------------------------------- | | | | echo exitonerror echo open !node | > > ftpcmds > > | | echo open !user !pass echo get | ftpcmds > > ftpcmds | | file1 file1 echo get file2 file2 | > > ftpcmds > > | | echo get file3 file3 echo quit | ftpcmds > > ftpcmds | | | > > 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 remotehosthame 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/iX prompt (:). Table 4-16. -------------------------------------------------- | | | | | !JOB FTPFILE,USERNAME.ACCT,PUB !RUN | | | FTP.ARPA.SYS OPEN 123.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. Table 4-17. ----------------------------------------------------- | | | program ftp_prog (input, output); Const | | | ----------------------------------------------------- | | | | | var | msglevel cr | = 0 = chr (13); : | | | cmdimage | string [80] : | | | cmderror | shortint; : | | | parmnum | shortint; | | | | | ----------------------------------------------------- | | | procedure HPCICOMMAND; intrinsic | | | ----------------------------------------------------- | | | begin | | | ----------------------------------------------------- Table 4-18. -------------------------------------------------------------- | | | | { ------------------------------------------------- | } | | ----- | | | | | -------------------------------------------------------------- | | | | { 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. | | | | | -------------------------------------------------------------- | | | | { ------------------------------------------------- | } | | ----- | | | | | -------------------------------------------------------------- Table 4-19. ------------------------------------------------------------------- | | | 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 the STDIN file FTPIN are listed below: Table 4-20. ------------------------------------------ | | | | | OPEN 123.50.42.32 USER remuser | | | rempass PWD DIR * GET file1 GET | | | file2 GET file3 QUIT | | | | ------------------------------------------ | | | | | | ------------------------------------------ Obtaining Status Information Use the STATUS command to obtain status information regarding the FTP client and server. The status information is useful for debugging purposes and for identifying the states and modes of the client and server peers. Table 4-21. ------------------------------------------------------------------- | | | ftp status Connected to xyz.cup.hp.com (22.11.138.29). | | (FTPINFO 40) Using ASCII mode to transfer files. (FTPINFO 25) | | Verbose mode on. (FTPINFO 22) Debugging off (debug=0). | | (FTPINFO 23) ExitOnError mode off. (FTPINFO 34) Interactive | | mode on. (FTPINFO 41) Lower case off. (FTPINFO 44) Store | | unique mode off. (FTPINFO 51) Receive unique mode off. | | (FTPINFO 53) Command tracing off. (FTPINFO 55) Data tracing | | off. (FTPINFO 57) Connection time-out value set to 120 | | seconds. (FTPINFO 49) 211- katsu FTP server status | | | ------------------------------------------------------------------- | | | | | Version A0007F06 Connected to abc.cup.hp.com | | | (25.33.144.142) Logged in as ,MANAGERSYS,PUB TYPE: | | | ASCII FORMat: Non-print; STRUcture: File; transfer | | | MODE: Stream No data connection. | | | | ------------------------------------------------------------------- | | | 211 End of status. ftp> | | | -------------------------------------------------------------------


MPE/iX 5.0 Express III Documentation