MainframeSupports
tip week 45/2007:

Maybe you have tried to execute the FTP command in batch on the mainframe. Then you may have discovered the very bad error handling that is the default for FTP errors. If a FTP command fails then it just continues executing the following commands and ends by returning a cond code of 0 despite the errors encountered. I do not have the imagination to think of a worse default set up. I think most operations departments has been or will be subject to this subtlety. I hope this tip will prevent further accidents.

I will start with an example showing an FTP step returning a cond code of 8 if any of the executed FTP commands fails. If all FTP commands executes successfully a cond code of zero is returned. FTP commands following the first failing FTP command will not be executed:

//FTPSTEP EXEC PGM=FTP,PARM='1.2.3.4 (EXIT=8'
//OUTPUT  DD SYSOUT=*
//INPUT   DD *
myftpusr
myftpswd
cd invalid_directory
pwd
quit
/*

The most important information in the above job step is the text in the PARM= parameter. First part is the IP address (1.2.3.4) or the FTP server name and the last part are the parameters after the left parenthesis. Here I have typed in EXIT=8 which is the option that makes the FTP execution stop after the first FTP command terminating with an error and makes the FTP command return a cond code of 8. It is enough to use option EXIT wihtout any cond code value. Then FTP works the same way as with a cond code, but it returns strange cond codes depending on the kind of error encountered. The cond codes returned are not in tune with normal cond code settings and I strongly advice you to use EXIT with a value.

It is possible to type in other parameters after the left parenthesis. It is nice to know that EXIT must be the first parameter after the left paranthesis. With regard to the FTP commands they must be located in DD name INPUT. When the IP-address is placed in the PARM field the first line in INPUT must contain a user-id and the second line must be the password belonging to the user-id. The FTP commands follows after these two lines. In the example I am trying to shift the current directory to a directory called invalid_directory. Most likely this directory does not exist which makes the command fail and the execution stop with a cond code of 8. If the directory should exist (probably by accident) the FTP command pwd prints out the full path to the directory your FTP session is currently working with. The last command (quit) terminates the FTP session. If you forget to type in quit the FTP program issues it for you.

I have located a manual describing the batch FTP program. Here is a link to the chapter about executing FTP in batch. I have already introduced the use of FTP directly from TSO back in week 19.

Previous tip in english        Sidste danske tip        Tip list