22
Sun, Dec
3 New Articles

FTP: Tricks of the Transfer

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

FTP was one of the first protocols used to transfer files between computers in the early days of the modern Internet. Years ago, I used to log on to the local college’s mainframe computer and FTP files to and fro. It was a fun protocol to learn, and it still is. FTP is a very handy mechanism for moving data between AS/400s or between an AS/400 and almost any other machine, including PCs and UNIX machines. FTP, like HTTP or Simple Mail Transfer Protocol (SMTP), is a standard TCP/IP protocol, which means that, no matter what system you are running, you will be able to communicate with any other system that also uses TCP/IP. In this article, I’m going to share some of the tips and tricks I’ve learned over the years for getting the most out of FTP.

Source Member Transfers

Figure 1 shows the FTP commands you’ll need to enter to retrieve a source member from an AS/400, as well as the responses you’ll get from the FTP server. Notice that the first command you enter after your user name and password, Change Directory (CD), changes the current directory of the host machine to the library BVSLIB. The next command, Local Change Directory (LCD), changes the local directory on your PC to c:download. This is the name of the directory on your local PC where you’ll store the files retrieved from the host.

The next command shown in Figure 1 is the GET command. This command allows you to send or retrieve a file from the host. The naming format for the file in this case is FILENAME.MEMBER. So, in this case, I am retrieving the member TESTPGM from the QRPGLESRC source file. Once the transfer is complete, I will have a file on my PC in the c:download directory named qrpglesrc.textpgm. This file will be a text file, and it can be opened or viewed with a program such as Windows Notepad.

Finally, the QUIT command is issued, which closes the connection to the host machine and, in some cases, ends the FTP client program.

PC to AS/400

The steps to send files to an AS/400 from a PC are exactly the opposite of the steps shown in Figure 1. Figure 2 shows a session that sends the TESTPGM member back to the source physical file QRPGLESRC in library BVSLIB. In this example, I used fully qualified names to illustrate how it works.


Multiple Files

The first two examples were pretty simple. But now I’ll show you how to send or retrieve multiple files from an AS/400. For example, if I wanted to download every member from the QRPGLESRC source file, I would use the Multiple GET (MGET) command. The opposite of MGET is the Multiple PUT (MPUT) command, which is used to send multiple files to a host machine.

Figure 3 shows the commands used for the MGET example. You’ll notice a new command, PROMPT, which tells the host system not to verify that I want to receive each member one at a time. In other words, if I didn’t use the PROMPT command, the host machine would ask whether I am sure that I want to download each particular member.

Trailing Blanks

One problem programmers face when using FTP as a client on the AS/400 is that it is set up as a default to trim trailing blanks from records. What this means is that, if you have a file to be transferred from the PC that has a record length of 250 characters but the longest record in the file is only 200 characters, the file that is created on the remote machine will also have a record length of only 200 characters, rather than 250. This may cause problems on the remote system if the application that needs to read that file is expecting a record length of 250 characters.

This problem is easily solved by using the FTP command TRIM . The TRIM command tells the AS/400 to trim or not to trim trailing blanks during the transfer. This command must be prefixed with the LOCSITE command, which says that the command is applied to the local machine (in this case, the AS/400).

Issuing the command LOCSITE TRIM 0 will turn off trimming. LOCSITE TRIM 1 will turn on trimming. LOCSITE TRIM will display the current mode of TRIM.

FTP Scripts

The next trick that I have found very useful is using a script—either predefined or dynamically created—to tell the FTP client what to do. I have used this method with both Windows and AS/400 FTP clients. While the method performs the same function on both platforms (i.e., telling the FTP client to read its commands from a file), the way it is done for each is fairly different.

To use a script for the AS/400 FTP client, you must use the Override with Database File (OVRDBF) command, which overrides the file INPUT and accesses the file and source member that contains the FTP commands. The standard INPUT and OUTPUT files used by FTP are normally the console running the FTP commands on the AS/400. That is, when an FTP command executes in a script, its output (if any) such as information messages, are directed to the display station the script is executing on. You can override the INPUT and OUTPUT files to a physical file on the AS/400 to capture the output from the FTP script so that any messages issued by the script will be suppressed and the user will not see them.

Figure 4 (page 74) shows the CL command that will tell the FTP client to read its commands from the member FTPSCRIPT1 in file QFTPSRC. The member can be static (hand-keyed with SEU) or built dynami-cally (with an RPG program, for example).

You can also redirect the output produced by the FTP session to a file; the OVRDBF command on the file named OUTPUT does this in Figure 5. In this case, the output will be stored in the file QFTPSRC, member OUT1. OUTPUT is appended to the file, so if you want it cleared before each run, you’ll have to do so yourself. If the file doesn’t already exist, it will be created by the system.

Using scripts with the Windows FTP client is similar. On the FTP command, you specify the file name that contains the FTP scripts. Simply use the -s option on the Windows 9x FTP command and tell it which file to use. For example, ftp


ftp.myserver.com -s:c:ftpscript1.txt tells the Windows FTP client to read its commands from the file script1.txt, located in the FTP directory. Static scripts can be built using Notepad, or the script can be built dynamically with anything from MS-DOS batch commands to Visual Basic.

Using AS/400 Save Files

The last trick, which a lot of people are asking about, is transferring a save file from the AS/400 to a PC platform for storage. I have found myself using this technique when a new machine arrives and I don’t have any tapes available for backups. Saving libraries to a save file and FTPing them to a PC or other server has helped me sleep better at night. This is also a useful technique for transferring save files to other users over the Internet.

Here’s how you do it: Save the objects on your AS/400, FTP them to your PC, attach the *SAVF to an email, and send it to a buddy across the country. When your buddy receives the file, he’ll FTP it to his own AS/400 and restore it. Worldwide object distribution made simple!

The first step is to create a save file on your AS/400 by using the Create Save File (CRTSAVF) command. Next, issue a SAVxxx command just as you would if you were saving objects to a tape, but, for the device type, select *SAVF. The command will then prompt you for the save file location. Once the save is complete, start an FTP session from your PC to the AS/400, switch to binary mode using the BIN command, and then issue a GET command to retrieve the save file. Figure 5 shows an example of this technique.

To restore the data to the AS/400, the steps are the same. First, create a save file on the AS/400. Next, start your FTP session to the AS/400, change to binary mode, and then issue a PUT command. The important parts are that you use binary mode and that you create the save file first. If you don’t create the save file first, a physical file will be created when you issue the PUT command. When you create a save file first, the system knows where to put the data. It will even tell you if you not in binary mode.

How Far Will You Take FTP?

I encourage you to experiment with FTP (on a test machine, of course!) to see what it can do for you. You can use FTP for simple file transfers, or you can use it as the backbone of a complex data transfer system. It all depends on how far you want to take it.

If you have a favorite FTP tip, feel free to send them to This email address is being protected from spambots. You need JavaScript enabled to view it. and the MC tech team may make them available in either a future article or in Tech Talk. We’re always looking for easier ways to perform tasks!

ftp> open 207.212.90.55
Connected to 207.212.90.55.
220-QTCP at MC170.
220 Connection will close if idle more than 166 minutes.
User (207.212.90.55:(none)): userid
331 Enter password.

Password:
230 STONE logged on.
ftp> cd bvslib
250 "BVSLIB" is current library.
ftp> lcd c:download
Local directory now C:Download.
ftp> get qrpglesrc.testpgm
200 PORT subcommand request successful.
150 Retrieving member TESTPGM in file QRPGLESRC in library BVSLIB.
250 File transfer completed successfully.
ftp: 11021 bytes received in 1.70Seconds 6.48Kbytes/sec.
ftp>

Figure 1: A simple FTP session will copy a source member to a PC.


ftp> open 207.212.90.55
Connected to 207.212.90.55.
220-QTCP at MC170.
220 Connection will close if idle more than 166 minutes.
User (207.212.90.55:(none)): userid
331 Enter password.

Password:
230 STONE logged on.
ftp> put c:downloadqrpglesrc.testpgm bvslib/qrpglesrc.testpgm
200 PORT subcommand request successful.
150 Sending file to member TESTPGM in file QRPGLESRC in library BVSLIB.
250 File transfer completed successfully.
ftp: 11021 bytes sent in 3.18Seconds 3.47Kbytes/sec.
ftp> ftp> open 207.212.90.55
Connected to 207.212.90.55.
220-QTCP at MC170.
220 Connection will close if idle more than 166 minutes.
User (207.212.90.55:(none)): userid
331 Enter password.

Password:
230 STONE logged on.
ftp> cd bvslib
250 "BVSLIB" is current library.
ftp> lcd c:download
Local directory now C:Download.
ftp> prompt
Interactive mode Off .
ftp> mget qrpglesrc.*
200 Representation type is ASCII nonprint.
200 PORT subcommand request successful.
150 Retrieving member TESTPGM in file QRPGLESRC in library BVSLIB.
250 File transfer completed successfully.
ftp: 11021 bytes received in 4.01Seconds 2.75Kbytes/sec.
200 PORT subcommand request successful.
150 Retrieving member TESTPGM2 in file QRPGLESRC in library BVSLIB.
250 File transfer completed successfully.
ftp: 9514 bytes received in 3.18Seconds 2.99Kbytes/sec.
200 PORT subcommand request successful.
150 Retrieving member TESTPGM3 in file QRPGLESRC in library BVSLIB.
250 File transfer completed successfully.
ftp: 12841 bytes received in 3.73Seconds 3.44Kbytes/sec.
200 PORT subcommand request successful.
150 Retrieving member TESTPGM4 in file QRPGLESRC in library BVSLIB.
250 File transfer completed successfully.
ftp: 12243 bytes received in 3.57Seconds 3.43Kbytes/sec.
ftp>

OVRDBF FILE(INPUT) TOFILE(QFTPSRC) MBR(FTPSCRIPT1)
OVRDBF FILE(OUTPUT) TOFILE(QFTPSRC) MBR(OUT1)
FTP RMTSYS(ftp.myserver.com)
DLTOVR FILE(INPUT OUTPUT) ftp> open 207.212.90.55
Connected to 207.212.90.55.
220-QTCP at MC170.
220 Connection will close if idle more than 166 minutes.
User (207.212.90.55:(none)): userid
331 Enter password.

Password:
230 STONE logged on.
ftp> cd qgpl
250 "QGPL" is current library.
ftp> lcd c:savefiles
Local directory now C:savefiles.
ftp> bin


Figure 2: The steps to send a file to the AS/400 are the opposite of those in Figure 1.

Figure 3: Use the MGET method in an FTP session to retrieve multiple files from an AS/400.

Figure 4: You can use CL commands to tell the AS/400 FTP client to read its commands from a file.

200 Representation type is binary IMAGE.
ftp> get bvslib
200 PORT subcommand request successful.
150 Retrieving member BVSLIB in file BVSLIB in library QGPL.
250 File transfer completed successfully.
ftp: 228096 bytes received in 73.71Seconds 3.09Kbytes/sec.
ftp>

Figure 5: Retrieve a save file from an AS/400 via an FTP session.


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: