Wednesday, May 14, 2008

Make a CL job to send data using FTP:

Create a physical file of 50 to 80 characters to hold the FTP commands. Name it something like FTPIN.
Then use DFU to enter the FTP commands. The first record should be your user ID and password. Then the following records have the remaining FTP commands.
For example, to sign on as davidmount with password of as400, then change directory to UPLOAD and then PUT a file, the records should look like:
davidmount as400
cd UPLOAD
put xyzzy.txt abc.csv
quit
You may also create a file for the output. Say... FTPOUT
Then, the CL to execute overides the specially named INPUT file and OUTPUT file.
The CL looks like:

OVRDBF FILE(INPUT) TOFILE(FTPIN)
OVRDBF FILE(OUTPUT) TOFILE(FTPOUT)
FTP '123.12.12.123'

What would normally be displayed on the screen as output is written to the FTPOUT file. This is very powerful. You can (with some effort), use FTP to get a directory of the files on a remote system. Then, you can read thru the directory (it's in the FTPOUT file) and then build other FTP scripts to GET specific files and even delete specific files.
In a related matter, to check to see if a transfer is complete, you must read through the FTPOUT file to see if you find the phrase "Transfer complete" in a record somewhere.
OS/400 will NOT return an error if you do not successfully transfer the data. It will simply write the output display to the OUTPUT file and consider this a successful execution of the FTP.

No comments: