Using CI Variables in FTP Commands

A common question we are asked is why Command Interpreter (CI) variables to not work as expected in batch jobs. As an example:


!job filexfer,manager.prod;outclass=lp,1
!comment Generate output file
!purge file100
!run prog100.prog.prod;xl="xl2.pub.prod"
!comment
!comment Transfer file to server via FTP. Name the file
!comment FILE000.yyyymmdd using today's date
!ftp.arpa.sys
open 192.168.54.1
user hp3000
cd /hp3000/acctg
ascii
put FILE100 file100.!hpyyyymmdd
quit
!eoj

CI Variable substitution means the Command Interpreter will substitute the value of a variable when it executes the command. In this case, the value of the CI variable HPYYMMDD is expected to be substituted, causing the command to look like this “put FILE100 file100.20001002” The reason that the above hilighted line does not work correctly is because the CI is not responsible for executing the command. It is being used as direct input to the FTP program. For the CI to substitute a character into a command it must have execute the command. In this case, FTP is responsible for processing the command, not the CI.

A simple workaround is to give the CI a chance to substitute the variable by creating an input file of the commands you want to execute, and then pipe those commands into the program you want to run. For this capability we turn to the ECHO command. The same job would look like this:


!job filexfer,manager.prod;outclass=lp,1
!comment Generate output file
!purge file100
!run prog100.prog.prod;xl="xl2.pub.prod"
!comment
!comment Transfer file to server via FTP. Name the file
!comment FILE000.yyyymmdd using today's date
!purge ftpinput
!build ftpinput;rec=-80,,f,ascii
!file ftpinput;acc=append
!echo open 192.168.54.1 >*ftpinput
!echo user hp3000 >*ftpinput
!echo cd /hp3000/acctg >*ftpinput
!echo ascii >*ftpinput
!echo put FILE100 file100.!hpyyyymmdd >*ftpinput
!echo quit >*ftpinput
!reset ftpinput
!ftp.arpa.sys <ftpinput
!eoj