Unattended File Transfers Using FTP
System administrators commonly initiate FTP sessions to other systems' FTP clients using the FTP client capability on the iSeries. Users could also connect to the iSeries FTP server with their systems (Windows, Linux, etc.) FTP client and transfer data.
When transfers must occur during off hours or at scheduled intervals, an automated or unattended FTP transfer may be used. iSeries, Windows, UNIX and Linux systems have the capability to provide unattended FTP data transfers. This article explains how to perform unattended FTP data transfers, both those initiated from the iSeries and those initiated from the remote system to the iSeries.
Because FTP is inherently an interactive process (users commands from an FTP client command line), we must provide a method where the FTP commands are coming from a different source - a file of commands. Obtaining these commands from a different source is known as redirection. We'll redirect the input to the FTP process from interactive commands being entered on a command line to obtain those same commands from a file.
The iSeries FTP client obtains commands from an input file (INPUT). The client can also optionally redirect the output to a file. This output redirection allows another program in the job stream to check the FTP transfer's status. The key for this technique is to override INPUT to a file containing the FTP commands. We may also wish to override an output file (OUTPUT) to a file containing the results or messages of the FTP operation. (Note: The file names INPUT and OUTPUT are used internally in the iSeries FTP client process and required to perform unattended FTP transfers.) Once the files have been overridden, we initiate the FTP transfer.
/* Clear the FTP results output file */
/* Override the input (commands) and output (results) files */
OVRDBF FILE(INPUT) TOFILE(MICHAEL/QFTPSRC) +
OVRDBF FILE(OUTPUT) TOFILE(MICHAEL/FTPRESULT)
/* Transfer the file using the commands in the FTPIN member */
/* Delete the overrides */
In the CL program (FTPTOWIN) above, the INPUT file is overridden to MICHAEL/QFTPSRC.FTPIN. This causes the FTP process to read the commands from the file rather than expecting input from the keyboard. Accordingly, the OUTPUT file is overridden to MICHAEL/FTPRESULT. This causes the FTP process to write the resulting messages from the FTP process to the file rather than to the display. The FTP command initiates the transfer with the remote system (FTPREMOTE) and the FTP command input is read from INPUT and the output messages written to OUTPUT. The program then deletes the overrides and ends. This program could be modified to start the iSeries FTP server (STRTCPSVR SERVER(*FTP)) before the FTP command and end the iSeries FTP server (ENDTCPSVR SERVER(*FTP)) after the FTP command. This may be useful if you don't wish to leave the FTP server running, perhaps for performance or security considerations.