HPlogo HP ARPA File Transfer Protocol User's Guide: HP 3000 MPE/iX Computer Systems > Chapter 4 Using FTP

Using FTP Commands in UDCs and Programs

» 

Technical documentation

» Feedback

 » Table of Contents

 » Glossary

 » Index

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:

ftp> EXITONERROR
ExitOnError mode on. (FTPINFO 33)
ftp> GET filex filey
200 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 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
FTPXFERFILES = 0
FTPREQFILES = 0
FTPREPLACE = true
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:

    parm node, user, pass
    continue
    purge ftpcmds,temp
     
    echo exitonerror
    echo open !node
    echo open !user !pass
    echo get file1 file1
    echo get file2 file2
    echo get file3 file3
    echo quit
    > > ftpcmds
    > > ftpcmds
    > > ftpcmds
    > > ftpcmds
    > > 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 (:).

!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.

program ftp_prog (input, output);
Const
 


var
msglevel
cr

cmdimage
cmderror
parmnum
= 0
= chr (13);

: string [80]
: shortint;
: 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 the STDIN file FTPIN are listed below:

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.

In the following example, both the client (abc.cup.hp.com) and server (katsu.cup.hp.com) are MPE/iX machines.

ftp>status
Connected to katsu.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 ,MANAGER.SYS,PUB
TYPE: ASCII
FORMat: Non-print; STRUcture: File; transfer MODE: Stream
No data connection.
211 End of status.
ftp>
Feedback to webmaster