FTP is one of the more common TCP/IP protocols used in the computer industry today. Like its cousins, Simple Mail Transfer Protocol (SMTP) and HTTP, FTP is a common TCP/IP protocol used by a variety of systems.
FTP is not as commonly known or used in the AS/400 world as it is on other platforms, such as UNIX and Microsoft Windows NT. I cant explain why this is, but I do know that I have used it for years and find it to be one of the most useful tools around. Using FTP, you can transfer data to and from the AS/400 with great ease. You can archive data files, libraries, or source or download data from the AS/400 to be used on another platform or another AS/400.
I personally use FTP to distribute software to the user via the Internet. To do this, I first create a save file on an AS/400. Then, I download that save file to my PC, attach a text file with installation instructions, compress the two files into a single zip file, then upload that zip file to my Web server. If youre not familiar with zip files, or how to use them, be sure to check out the article Zip into the Future by Shannon ODonnell in the October 1999 issue of MC. Once on the Web server, a user can download the zip file and use it to install my software on his AS/400. Installation and storage is actually simple, yet I find users are sometimes unfamiliar with using FTP and need a little extra assistance. This led me to conclude that quite a few AS/400 users could use information explaining how, when, and why to use FTP.
Are You Being Served?
Whenever you are going to send or receive files from a machine, the server machine requires an FTP server. An FTP server is a program running on a machine that accepts requests for connections of file transfers from another machine. The FTP server takes requests from a client, usually consisting of commands that will retrieve or send files to the server. OS/400 comes with its very own FTP server, which works rather well. The server also provides you with exit points in which you can add exit programs for added security or anonymous logon support. These exit points allow you to run certain programs before a command is run. So, your exit program that is assigned to the exit point can decide if the command should be run or not.
Think of an FTP server as a librarian. When you go to the library, you ask the librarian for a certain book and she helps you find and retrieve that book. She also takes
books from you and puts them back on the shelf when you are finished reading them. She also verifies that you can check out books by issuing you a library cardthe same way an FTP server normally requires a user ID and password. In the same sense, an FTP server acts as a librarian for your data.
Making the Connection
The AS/400, as do most server machines, comes equipped with an FTP server. Starting the FTP server requires you to use the START TCPIP SERVER (STRTCPSVR) command, specifying *FTP for the server name. The command is as follows:
STRTCPSVR SERVER(*FTP)
You can verify if your FTP server is running by viewing active jobs that start with QTFTP. Using the command WRKACTJOB JOB(QTFTP*) will display, if active, the jobs running for the FTP server.
Once the FTP server is running on the AS/400, it is ready to accept communications and file transfers from a client. An FTP session is initiated by a user issuing an FTP connect command from his client machine, specifying the remote machine as the target. From your PC, you can start an FTP session by clicking the Start button, selecting the Run option, then entering FTP in the command prompt. These steps should bring up an FTP session in a DOS window. To initiate the connection, use the command OPEN followed by the IP address of your AS/400. If your FTP server is running on your AS/400, you should receive a prompt that asks you for your user ID, as shown in Figure 1 (page 54). Here you will enter your AS/400 user ID. After you have entered your user ID, you will be prompted for a password. Again, this is probably the same password you use to log on to the AS/400 in most other situations.
You can also start an FTP session from your AS/400 by using the FTP command. The FTP command accepts an IP address or domain name as a parameter, and this tells the FTP client where to establish an FTP connection. Just remember that your FTP server does not need to be running on your AS/400 to start an FTP session on the same AS/400. This is because the FTP command starts a client job requesting a connection with a machine running an FTP server.
Common Commands
Once you are logged on, it is a good idea to use the HELP command. This will show you all the commands available for you to use. You can see an example of the HELP command in Figure 2. In addition to the HELP command, you can use the REMOTEHELP command on most systems. This command will show you what commands the server allows.
Of the commands available, there are a few that are more commonly used. These commands are shown in Figure 3. Most of the commands are self-explanatory. The GET and PUT commands are used most frequently, since the purpose of FTP is to send or retrieve files to or from a remote machine, respectively. The CHANGE DIRECTORY (CD) and LOCAL CHANGE DIRECTORY (LCD) commands can be used to position where a file will be retrieved from or put to, depending on the command being used. CD changes the current directory on the server machine, and LCD changes the current directory on the local, or client, machine. As with the CD command, some commands are similar to DOS commandsthe DIR command, which lists the contents of a directory, comes to mind.
Which File System?
As you may know, the AS/400 contains a couple of unique types of file systems. These are commonly known as the QSYS file system and the ROOT file systemboth of which are contained within the AS/400 Integrated File System (AS/400 IFS).
AS/400 users know the QSYS file system as the library file system. All libraries on the AS/400 are contained within a single library known as QSYS. These libraries hold your files, source members, and programs. The ROOT file system is more common to a PC file system, containing directories, subdirectories, and files.
Using FTP with each of these systems is different. Setting up FTP to use each of these systems also requires a couple of special commands. The FTP Name Format (NAMFMT) command tells the AS/400 FTP server which file system you will be making requests from. For example, the following command tells the AS/400 that you wish to retrieve files using the ROOT file system naming structure, similar to running an FTP session on a PC:
QUOTE SITE NAMFMT 1
The filenames are specified in the format /directory1/directory2/.../filename. On the flip side, this command tells the AS/400 that you are going to use the library method of FTP communications:
QUOTE SITE NAMFMT 0
Youll notice the use of the QUOTE SITE commands in the previous examples. The reason for this is the NAMEFMT command is an AS/400 command. To run a command on the AS/400 from the PC FTP client, use the QUOTE command to say run this command on the server. If you were using the AS/400 as a client, you would omit the QUOTE SITE portion of the command.
You can use the CD command to change which library you are currently using. Then, for retrieving files, you use the format [lib/]filename[.member] to tell the AS/400 which file to retrieve by using the GET command, or what to name the file when it gets there by using the PUT command. The library name is optional, and, if not used, the current library will be used. If a member name is not specified following the file name, the member name will be assumed to be the same as the file name.
Files in libraries can be accessed not only in NAME FORMAT 0 but also in NAME FORMAT 1. The format used is as follows:
/QSYS.LIB/libraryname.LIB/filename.FILE/
member.MBR.
Basically, all you need to remember is to always start with /QSYS.LIB, then add the name, followed by a period and the appropriate attribute found on a WORK WITH OBJECT (WRKOBJ) command, minus the leading asterisk.
One oddity that I have found is, if I am using NAME FORMAT 1 and wish to switch to NAME FORMAT 0, I must first change the directory to /QSYS.LIB and then issue the command to change to NAME FORMAT 0.
Watch the Mode!
The transfer format of the data may also be important when transferring files with FTP. There are normally two modes of file transfer. The first is ASCII, in which the file is downloaded as an ASCII file. This is mainly used for uploading or downloading source members so the source members are treated as text files. The AS/400 FTP server handles the EBCDIC-to-ASCII translation by using tables that are available on the system. The table used can be changed with the CHANGE FTP ATTRIBUTES (CHGFTPA) command and by specifying a new table on the TBLFTPOUT or TBLFTPIN parameters. There is a table for both input and output, so changing the correct one will make a difference. Using the FTP command ASCII on the FTP command line will tell the server to transfer the file in ASCII mode.
The second mode of transfer is binary. This format is usually used for uploading or downloading save files or any other type of file or object that you dont want corrupted by the conversion from EBCDIC to ASCII. Image files stored in the AS/400 IFS are good examples of this type of file. Entering the command BINARY, or BIN, on the FTP command line will tell the server to send the file in binary mode. One nice thing about the AS/400 is that, if you try to upload or download a save file in ASCII mode, it will actually give you an error message telling you that binary mode is required for save files.
One thing to note when using FTP to transfer data files to your PC is, if the file contains numeric data, the numeric data will not be translated correctly. Files that contain only character data, however, are transferred without any problems. If you wish to transfer a file from your AS/400 to your PC to be used in another database, it is best to first copy the physical file into a comma-delimited file, then FTP the result. This can be done using the COPY TO IMPORT FILE (CPYTOIMPF) command.
FTP Tricks
Once youve used FTP long enough to feel comfortable with it, you can start using some tricks to make your job easier. In the August issue of Midrange Computing, there is an article titled FTP: Tricks of the Transfer, which will help you with these tricks. Tricks such as creating dynamic FTP scripts, downloading multiple files at once, and even downloading source from your AS/400 are included in this article.
FTP may be new to some people, but its definitely one of the easier TCP/IP protocols to use, and it is one of the most beneficial.
REFERENCES AND RELATED MATERIALS
FTP: Tricks of the Transfer, Bradley V. Stone, MC, August 2000
OS/400 TCP/IP Configuration and Reference V4R4 (SC41-5420-03, QB3ANL03)
Zip into the Future, Shannon ODonnell, MC, October 1999
ftp> open xxx.xxx.xxx.xxx
Connected to xxx.xxx.xxx.xxx.
220-QTCP at xxx.xxx.xxx.xxx.
220 Connection will close if idle more than 10 minutes.
User (xxx.xxx.xxx.xxx:(none)): ftp> help
Commands may be abbreviated. Commands are the following:
! delete literal prompt send
? debug ls put status
append dir mdelete pwd trace
ascii disconnect mdir quit type
bell get mget quote user
binary glob mkdir recv verbose
bye hash mls remotehelp
cd help mput rename
close lcd open rmdir
Figure 1: This is an example initial prompt for an FTP connection.
Figure 2: Issuing the HELP command once youre signed onto an FTP server returns the commands available to you.
Command Action
OPEN Open a connection to an FTP server CLOSE Close a connection to an FTP server QUIT Close a connection to an FTP server and exit the FTP client program
GET Get a file from the FTP server
PUT Put a file to the FTP server
DIR List the current directory contents
CD Change the current directory
LCD Change the current directory on the local machine HELP Display a list of available commands
Figure 3: The most commonly used FTP commands are self-explanatory.
LATEST COMMENTS
MC Press Online