21
Sat, Dec
3 New Articles

Five Steps to Running Batch FTP from Your AS/400

Typography
  • 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 (www.helpsystems.com/products/ 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 192.168.10.1 IP address, you would enter your command this way:

FTP RMTSYS(‘192.168.10.1’)


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 (192.168.10.1) 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:

NAMEFMT 0

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:

PUT HERTVIK/CUSTOMER HERTVIK/CUSTOMER

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

QUIT

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.

REI
USER HERTVIK PASSWORD
NAMEFMT 0
PUT HERTVIK/CUSTOMER HERTVIK/CUSTOMER
QUIT

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

PGM

OVRDBF FILE(INPUT) TOFILE(HERTVIK/SOURCE) +

MBR(FTPINPUT)

CLRPFM FILE(HERTVIK/SOURCE) MBR(FTPOUTPUT)

OVRDBF FILE(OUTPUT) TOFILE(HERTVIK/SOURCE) +

MBR(FTPOUTPUT)

FTP RMTSYS(192.168.10.1)

DLTOVR FILE(*ALL)

ENDPGM

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 forums.midrangecomputing.com at address 192.168.10.1
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.
0024.00 > PUT HERTVIK/CUSTOMER HERTVIK/CUSTOMER
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.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: