Every AS/400 running V3R1 has TCP/IP built right into the operating system. This is also true for most other popular computer systems today, whether they're made by IBM or anyone else. TCP/IP has become the standard protocol for networking computers from multiple vendors.
TCP/IP has a common set of applications that allow you to communicate with other systems on a network (see "AS/400 Telnet," MC, September 1995). In this article, I'll discuss one of those applications?the AS/400's implementation of File Transfer Protocol (FTP).
FTP is an application that allows you to send and receive copies of files to or from one computer system to another. The main advantage of using FTP is that it is supported on a wide variety of platforms. So, for example, if you need to transfer files from an AS/400 to a UNIX system, FTP will get the job done.
On the AS/400, file transfers have traditionally been accomplished either with the Send Network File (SNDNETF) command over a SNADS network, or by using a PC application such as the Client Access File Transfer facility. However, many non-IBM systems don't cooperate with SNADS or Client Access. FTP can be used in place of either of these two methods to accomplish a similar task with a multitude of other systems?IBM and non-IBM. Let's briefly take a look at the pros and cons of using FTP on the AS/400.
Pros and Cons
You can use FTP to transfer object types other than files by saving them into a save file prior to transferring them. If the other system is an AS/400, you can restore the objects in the save file after the file transfer. However, even if the other system is not an AS/400, you can transfer data to and from save files, which isn't possible with Client Access (not directly anyway). So, for example, you could save an AS/400 program into a save file and use FTP to send the contents of the save file to a PC file. You could then give that PC file to someone who could use FTP to send it back to a save file on another AS/400. He would be able to restore the program to his system. No special programming is required to accomplish this. In addition to supporting save file data, FTP supports transferring documents, as well as files stored on optical drives.
The disadvantage of FTP is that it supports only minimal data type translation capabilities when sending files to a system other than an AS/400. For example, while it will translate data from EBCDIC to ASCII, it won't translate packed decimal fields to character data. If you need to transfer this type of data to anything except another AS/400, you'll need to write a program to convert the data into a format that the other system can recognize. FTP also won't allow you to perform any type of record selection, as is possible with Client Access File Transfer. You either have to transfer the entire file or nothing at all.
Now that you know what some of FTP's abilities and limitations are, let's take a closer look at the AS/400 implementation. There are two sides to the AS/400 FTP application. The FTP server handles requests from other systems, and the FTP client allows you to access files on other systems.
The FTP Server
Before using FTP on the AS/400 for the first time, you'll need a basic TCP/IP configuration as described in "Configuring TCP/IP on the AS/400," MC, August 1995. The TCP/IP Connectivity Utilities/400 licensed program, which is included with the base operating system at no extra charge, ships with FTP servers preconfigured. You can view or change the FTP server configuration by prompting the Change FTP Attributes (CHGFTPA) command, as shown in 1.
Before using FTP on the AS/400 for the first time, you'll need a basic TCP/IP configuration as described in "Configuring TCP/IP on the AS/400," MC, August 1995. The TCP/IP Connectivity Utilities/400 licensed program, which is included with the base operating system at no extra charge, ships with FTP servers preconfigured. You can view or change the FTP server configuration by prompting the Change FTP Attributes (CHGFTPA) command, as shown in Figure 1.
You'll probably want to leave most of the FTP attributes set to their default configurations. However, you may want to consider changing a couple of them. The Number of initial servers (NBRSRV) parameter defaults to 3. This number represents the number of FTP servers that start when either the Start TCP/IP (STRTCP) or Start TCP/IP Server (STRTCPSVR) command is run. Having multiple FTP server jobs running improves the performance of initiating an FTP session when multiple users attempt to connect at the same time. If you anticipate serving many FTP users, you may need to increase this value. The other parameter you may want to consider changing is Inactivity timeout (INACTTIMO). This value represents the number of seconds the system allows an FTP connection to remain inactive before it is ended. The default value is 300, which represents 5 minutes. If you're accessing your AS/400 through FTP and find that you're constantly receiving error messages that say your connection was closed by the remote host, you may want to consider increasing this value.
The FTP Servers need to be started before any other systems can make FTP requests. Normally, this happens automatically when you run the STRTCP command (unless you've changed the AUTOSTART parameter to *NO on the CHGFTPA command). You can verify that the FTP servers are active by looking for job names, starting with QTFTP in subsystem QSYSWRK. If you see these jobs, your system should be ready to accept FTP requests from an FTP client.
The FTP Client
You can use two commands to start the FTP client: either the FTP command or the Start TCP/IP FTP (STRTCPFTP) command. Both commands are identical. The FTP command has only one required parameter, as shown in 2. The Remote system (RMTSYS) parameter is where you enter the host name of the system you want to connect to. The host name can be defined in the Work with TCP/IP host table entries option on the Configure TCP/IP menu (GO CFGTCP). Alternatively, you can specify *INTNETADR for the host name and specify the IP address of the system you want to access in the INTNETADR parameter.
You can use two commands to start the FTP client: either the FTP command or the Start TCP/IP FTP (STRTCPFTP) command. Both commands are identical. The FTP command has only one required parameter, as shown in Figure 2. The Remote system (RMTSYS) parameter is where you enter the host name of the system you want to connect to. The host name can be defined in the Work with TCP/IP host table entries option on the Configure TCP/IP menu (GO CFGTCP). Alternatively, you can specify *INTNETADR for the host name and specify the IP address of the system you want to access in the INTNETADR parameter.
Once FTP connects with the remote system, you'll be placed into an interactive FTP session, as shown in 3. The remote system will prompt you for your user ID and password. Once those are validated, you can begin using FTP subcommands. There are a number of standard FTP subcommands, as shown in 4.
Once FTP connects with the remote system, you'll be placed into an interactive FTP session, as shown in Figure 3. The remote system will prompt you for your user ID and password. Once those are validated, you can begin using FTP subcommands. There are a number of standard FTP subcommands, as shown in Figure 4.
Since the primary purpose of FTP is to transfer files, the two subcommands you'll probably use most are get and put. Use the get subcommand to receive a file and put to send a file. The syntax of the commands are as follows:
get remotefile localfile put localfile remotefile
Refer to the accompanying sidebar, "AS/400 FTP Naming Formats," for information on the naming formats for the local and remote files. When you're finished using FTP, use the quit subcommand to end the session.
Batch FTP
Another way to use FTP is from within a batch job. This method consists of three components:
1. A CL program or REXX procedure
2. An input file containing FTP subcommands
3. An output file for FTP messages
An example of this technique is shown in 5. The CL program executes two Override Database File (OVRDBF) commands. The first overrides the file INPUT to member FTPCMDS in file QTXTSRC. This causes FTP to read the source member instead of waiting for keyboard input from the user. The second command overrides file OUTPUT to member FTPLOG in file QTXTSRC. This causes FTP to write its output to the source member instead of to the screen. The FTP command is then run to access a remote system. When this command is run, the FTP subcommands in the FTPCMDS source member are executed and the output from the FTP session is written to the FTPLOG source member.
An example of this technique is shown in Figure 5. The CL program executes two Override Database File (OVRDBF) commands. The first overrides the file INPUT to member FTPCMDS in file QTXTSRC. This causes FTP to read the source member instead of waiting for keyboard input from the user. The second command overrides file OUTPUT to member FTPLOG in file QTXTSRC. This causes FTP to write its output to the source member instead of to the screen. The FTP command is then run to access a remote system. When this command is run, the FTP subcommands in the FTPCMDS source member are executed and the output from the FTP session is written to the FTPLOG source member.
A word of caution when using this technique: The user ID and password are stored unencrypted in the FTPCMDS source member. To alleviate the security risk that this could pose, be sure not to leave this source member on your system when you're through using it.
The Choice Is Yours
With FTP, IBM offers yet another way to transfer files. The strengths of FTP lie in its cross-platform capabilities, but you can also use it between like systems. FTP is a versatile tool. While it may not be the best choice in every situation, it has capabilities you won't find in any other application. When you need it, nothing else will do. As TCP/IP grows in popularity, the demand for cross-platform tools such as FTP also grows. The next time you need to transfer files between unlike systems, think about using FTP. It might just be your only choice.
Robin Klima is a senior technical editor for Midrange Computing.
REFERENCE
OS/400 TCP/IP Configuration and Reference (SC41-3420, CD ROM QBKANL00).
The AS/400 File Transfer Protocol
Related Reading
AS/400 Telnet ? September 1995
Configuring TCP/IP on the AS/400 ? August 1995
Using TCP/IP with Windows ? August 1995
The AS/400 File Transfer Protocol
AS/400 FTP Naming Formats
AS/400 FTP uses two naming formats: 0 and 1. You can switch between the two formats with the namefmt subcommand followed by 0 or 1. Namefmt 0 (the default) is a naming format only for the library file system. It uses the following formats:
libname/filename.mbrname or libname/savfname
Namefmt 1 is a naming format for both the hierarchical file systems and the library file system. This format allows you to specify documents, files stored on optical drives, and library system files.
To specify documents in the document library system, use this format:
/QDLS/foldername.ext/filename.ext
To specify files on optical drives, use the following:
/QOPT/volname/dirname/filename.ext
To specify save files, use the following:
/QSYS.LIB/libname.lib/filename.savf
To specify any other file, use the following:
/QSYS.LIB/libname.lib/filename.file/mbrname.mbrThe AS/400 File Transfer Protocol
Figure 1: The CHGFTPA Command
The AS/400 File Transfer Protocol
Figure 2: The FTPCommand
The AS/400 File Transfer Protocol
Figure 3: The Interactive FTPSession
The AS/400 File Transfer Protocol
Figure 4: FTP Subcommands
Command Description ACCT Send Account Information APPEND Append a Local File Member to a Remote File ASCII Change File Type to ASCII BINARY Set Transfer Type to Image CD Change Working Directory or Library CDUP Change to Parent Directory CLOSE End an FTP Session with the Remote System DEBUG Control Display of Server Subcommands Sent to Remote System DELETE Delete a File on a Remote System DIR List Directory Entries, Libraries, or Files EBCDIC Change File Type to EBCDIC GET Copy a File from a Remote System to the Local System HELP Getting Help for FTP Subcommands LCD Change Working Library or Folder on Local System LOCSTAT Display Local Status Information LPWD Display Working Library, Folder, or Directory on Local System LS List Remote File Names LTYPE Local Type MDELETE Delete Multiple Files on a Remote System MGET Copy Multiple Files from a Remote System to the Local System MKDIR Make Directory MODE Specify Transmission Mode of Data MPUT Send Multiple Files from the Local System to a Remote System NAMEFMT Select File Naming Format NOOP Check Remote Server Response OPEN Connect to FTP Server on a Remote System PASS Send Your Password PUT Copy a File Member from the Local System to a Remote System PWD Display Current Directory, Folder, or Library QUIT Disconnect from a Remote System and End an FTP Session QUOTE Send a Subcommand to an FTP Server REINITIALIZE Reinitialize Session between Systems RENAME Rename a File on a Remote System RESET Reset the Server Reply Queue RMDIR Remove Directory SENDPORT Specify Whether a PORT Subcommand Is Sent SENDSITE Specify Whether a SITE Subcommand Is Sent SITE Send Information Used by a Remote System STATUS Retrieve Status Information from a Remote System STRUCT Specify File Structure SUNIQUE Control Overwriting of Files SYSCMD Pass an AS/400 CL Command to Your Local AS/400 System SYSTEM Remote System Description TYPE Specify File Transfer Type USER Send Your User ID to the Remote System VERBOSE Control of Text Display of Error Reply Messages
The AS/400 File Transfer Protocol
Figure 5: FTP Batch Example
CL Program FTPCL PGM OVRDBF FILE(INPUT) TOFILE(QTXTSRC) MBR(FTPCMDS) OVRDBF FILE(OUTPUT) TOFILE(QTXTSRC) MBR(FTPLOG) FTP RMTSYS(MC) DLTOVR FILE(INPUT OUTPUT) ENDPGM Source Member FTPCMDS klima mypaswrd get qgpl/invtrypf qgpl/invtrypf quit Source Member FTPLOG Output redirected to a file. Input read from specified override file. Connecting to host name MC at address 140.100.10.13 using port 21. 220-QTCP at MC. 220 Connection will close if idle more than 5 minutes. 215 OS/400 is the remote operating system. The TCP/IP version is "V3R1M0". Enter login ID (klima): 331 Enter password. 230 KLIMA logged on. 250 Now using naming format "0". 257 "$KLIMA" is current library. Enter an FTP subcommand. > get qgpl/invtrypf qgpl/invtrypf 200 PORT subcommand request successful. 1150 Retrieving member INVTRYPF in file INVTRYPF in library QGPL. 250 File transfer completed successfully. 330 bytes transferred in 13.110 seconds. Transfer rate 0.025 KB/sec. Enter an FTP subcommand. > quit 221 QUIT subcommand received.
LATEST COMMENTS
MC Press Online