17
Wed, Apr
5 New Articles

The ABCs of FTP

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

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 can’t 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 you’re not familiar with zip files, or how to use them, be sure to check out the article “Zip into the Future” by Shannon O’Donnell 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 card—the 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 commands—the 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 system—both 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

You’ll 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 don’t 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 you’ve 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 it’s 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 O’Donnell, 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 you’re 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.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

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: