Five Steps to Running Batch FTP from Your AS/400

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

If you’re just getting started with OS/400 FTP, you probably found that it didn’t take long to master the basics. After all, FTP is one of the key TCP/IP utility programs, and IBM’s OS/400 version isn’t much different from the implementations provided in the UNIX, Linux, or Windows environments.

Now that you’re manually using your AS/400 (iSeries) as an FTP server or client, and you’re firing up OS/400-centric FTP sessions with impunity, it’s time to take the next step: automating your FTP file transfers so that they can be called from inside a CL program or from an automatic scheduling program, such as Help/Systems’s Robot SCHEDULE product ( schedule.html). The good news is that automated FTP from an iSeries and AS/400 is easier than you think. It’s just a matter of following a few simple steps to set up a fully functional FTP transfer that can be called any time you wish in a batch program without any user intervention whatsoever. Here’s my quick five-step process for automating FTP transfers inside OS/400.

Step One: Test Your FTP Session Manually

Before you can automate an FTP transfer, you need to ensure that you can complete the transfer manually. To that end, it’s always wise to manually test out the specific command sequence that you’ll be using inside an automatic FTP transfer. Figure 1 shows some simple FTP commands for transferring a file from one AS/400 or iSeries to another. What I want to do is look at the manual process for running a specific FTP transfer, and then translate those steps to an automatic FTP that can be kicked off inside a CL program in a batch job.

Command 1 in Figure 1 shows you how to start an interactive FTP session by running the Start TCP/IP File Transfer (FTP) command. If you wanted to start an FTP session with another AS/400 at the IP address, you would enter your command this way:


Alternatively, you could set up an entry in the TCP/IP Host Table (accessed by selecting option 10 from the Configure TCP/IP [CFGTCP] menu) that associates an IP address ( with a specific host name (e.g., Remote400). In this case, if you wanted to use a host name to start your AS/400-to-AS/400 FTP session, you would enter the FTP command this way:

FTP RMTSYS(Remote400)

Once the session is established, OS/400 FTP will prompt you for a valid user name and password to log onto the target AS/400. After you enter these values, OS/400 starts the FTP session with the remote AS/400 host.

Now, because you’re performing an AS/400-to-AS/400 transfer, command 2 in Figure 1 (the NAMEFMT 0 subcommand) explicitly states that you should be using the file naming format 0—which allows you to specify only DB2/400 library names and file names—rather than AS/400 Integrated File System (AS/400 IFS) file naming conventions for the transfer. (See my article, “The One AS/400 FTP Command You Must Understand,” AS/400 Network Expert, November/December 1999). As shown in Figure 1, command 3 then copies a file called CUSTOMER in the library HERTVIK of my client AS/400 to the same library on the target host server AS/400 by using the FTP PUT statement. Finally, command 4 closes the FTP session and returns the user to the OS/400 command line via the FTP QUIT command.

Step Two: Setting Up the Transfer for Batch FTP

Now that you know the steps for a manual transfer and you have tested the manual FTP transfer skeleton, you can convert this procedure to a batch process that can be called from a CL program. In turn, you can set up the CL program to run from the scheduling software so that this transfer runs on a timed basis. The drill now is to convert the processes you created for the manual transfer into an automated process using three steps:

• You must set up a text file that contains the FTP commands to be executed. This file will serve as the input file for the automated FTP statement.

• You must set up a text file that contains the output of the FTP commands that have executed. This will be the FTP results (output) file.

• You must set up a CL program that runs the batch FTP using the commands stored in the FTP input file and stores the results of the transfer in the FTP output file.

Step Three: Setting Up the FTP Input File

Collect and transfer the manual commands into a single text file member that can be pulled into the batch FTP CL program. I performed this task for my example, and I came up with a text file that contains the commands listed in Figure 2.

For automated FTP, you must set up an FTP batch input member that stores all the FTP commands to execute from an OS/400 CL program automatically. The commands listed in Figure 2 help with the transfer in the following way:

• Because you’ll establish the FTP session in the CL program (which I’ll explain in this article), there is no need for an FTP OPEN command.

• The REI FTP command is the Reinitialize Session command, which is supported for OS/400 FTP logins. REI (which can be typed in as REIN on some systems) returns your session to the state it was in when the FTP session first started. You need to reinitialize your FTP session to sign onto your target AS/400 as a specific user via the FTP USER

command on the next line. Your batch transfer might fail if you don’t enter this command before the USER command.

• The USER HERTVIK PASSWORD command attempts to sign onto the remote AS/400 server with user profile HERTVIK and password PASSWORD. This command is the weak link of batch FTP because, like most client/server programs, it forces you to hard- code a password within your batch process. However, once you are signed on, you have the authority to transfer files between the two systems.

• The NAMEFMT 0, PUT HERTVIK/CUSTOMER HERTVIK/CUSTOMER, and QUIT commands are exactly the same as the commands you entered for the manual process.

The best place to store these commands is in a text file member (member type TXT) in an OS/400 source file. Because the drill requires you to override an OS/400 physical file member inside a CL program, an OS/400 physical file member is the only place where you can store these commands. You cannot store these FTP input commands in a text file inside the AS/400 IFS Root directory or any other directory in the AS/400 IFS.

To create the FTP input file, I used PDM to create an FTPINPUT source file text member (type TXT) in my HERTVIK/SOURCE file. I then entered the commands listed in Figure 2 and saved my member. When it’s time to run the batch FTP program, my FTP statement will access this source member to retrieve the commands to execute.

Step Four: Setting Up the FTP Output File

The next step is to create another text source file member (type TXT again) called FTPOUTPUT that will contain the results of the automated FTP transfer after you finish running the program. In a manual FTP session, the error messages and confirmation are displayed on the screen. This isn’t possible with a batch FTP program, and you need to redirect the FTP output. In this case, I am choosing to send the output to another source file member that I can review after the batch FTP transfer is complete.

Step Five: Setting Up Your FTP CL Program

Figure 3 shows the CL program that I set up to perform my batch FTP transfer. Whenever I transfer this particular file to another AS/400 or iSeries, I run this program and the batch transfer automatically completes. Here’s how it works:

• The first Override with Data Base File (OVRDBF) command changes all references to the INPUT file to the FTPINPUT source file member that I created in the HERTVIK/SOURCE file. When called in batch mode, FTP will automatically accept commands that originate from the designated INPUT file.

• The Clear Physical File Member (CLRPFM) command clears out any old messages from the FTP output file member FTPOUTPUT before the transfer begins. If you don’t clear this member, the new messages are appended to the bottom of the old messages listed in this source file member.

• The second OVRDBF command changes all references to the OUTPUT file to the FTPOUTPUT source file member I created. Rather than outputting the results of my FTP commands to a display, the command redirects those results to my FTPOUTPUT source file.

• The FTP command then runs, designating the remote system to which your AS/400 or iSeries should connect in order to create a transfer session (which is why you didn’t need to use an FTP OPEN command in your FTPINPUT text file). The FTP command then

processes the commands listed in the FTPINPUT source member for the transfer and places the results of that transfer in the FTPOUTPUT source member. To view the results of the batch FTP transfer, you can view the FTPOUTPUT source member in your SEU editor. Also, because this FTPOUTPUT file is nothing more than an OS/400 file member, you can use it as input for a CL or RPG program to process the output information and perform certain actions based on whether the command executed correctly or not. See Figure 4 for a sample of the type of output messages a batch FTP session produces.

• The Delete Override (DLTOVR) command deletes the INPUT and OUTPUT overrides that were used in the program.

I Told You It Was Easy

Once you understand how easy it is to create a batch FTP transfer, you’ll be using it to set up transfers automatically all over the place. Give it a try. It will make life easier for your FTP processing.

Command 1: Start the FTP session with the remote AS/400 by using the OS/400 FTP command:

FTP RMTSYS(ip_address) or FTP RMTSYS(host_name)

OS/400 FTP will automatically prompt the user for a valid OS/400 user profile name and password during this
stage. At this point, your FTP session is started and you can enter FTP commands.

Command 2: Specify that this is a DB2/400-only file transfer to simplify your file naming convention by
using the NAMEFMT command, as follows:


Command 3: Copy the CUSTOMERS file in the HERTVIK library to the same file and library name on the target
host machine by using the FTP PUT command:


Command 4: End the FTP session by entering the FTP QUIT Command:


This ends your FTP session and returns you to the OS/400 command line.

Figure 1: Use these commands to perform the example manual FTP transfer.


Figure 2: Enter these commands into the FTP input member, FTPINPUT.










Figure 3: This simple CL program runs the file transfer.

*************** Beginning of data *************************************
0001.00 Output redirected to a file.
0002.00 Input read from specified override file.
0003.00 Connecting to host at address
0004.00 port 21.
0005.00 220-QTCP at MC170.
0006.00 220 Connection will close if idle more than 166 minutes.
0007.00 Enter login ID (hertvik):
0008.00 331 Enter password.
0009.00 OS/400 is the remote operating system. The TCP/IP version is "V4R4M0".
0010.00 250 Now using naming format "0".
0011.00 Enter an FTP subcommand.
0012.00 > USER HERTVIK *****
0013.00 331 Enter password.
0014.00 230 HERTVIK logged on.
0015.00 OS/400 is the remote operating system. The TCP/IP version is "V4R4M0".
0016.00 250 Now using naming format "0".
0017.00 257 "HERTVIK" is current library.
0018.00 Enter an FTP subcommand.
0019.00 > NAMEFMT 0
0020.00 250 Now using naming format "0".
0021.00 Server NAMEFMT is 0.
0022.00 Client NAMEFMT is 0.
0023.00 Enter an FTP subcommand.
0025.00 227 Entering Passive Mode (192,168,10,1,21,152).
0026.00 150 Sending file to member CUSTOMER in file CUSTOMER in library HERTVIK
0027.00 250 File transfer completed successfully.
0028.00 63 bytes transferred in 0.005 seconds. Transfer rate 12.902 KB/sec.
0029.00 Enter an FTP subcommand.
0030.00 > QUIT
0031.00 221 QUIT subcommand received.
0032.00 Output redirected to a file.
0033.00 Input read from specified override file.

Figure 4: Always check the batch FTP output file after a batch transfer completes.