Stuff
OS/400 Edition
Volume 1, Number 13 -- July 18, 2002

FTP Basics: Batch Processing


by Shannon O'Donnell

As more and more AS/400 shops move to PC-based development tools, more and more AS/400 programmers are having to learn PC-based functions and commands. One of these, which has become the de facto standard for file transfers, is File Transfer Protocol. FTP is one of those TCP/IP utilities that has been around for years and is really easy to use. But did you know that you can use FTP for batch file transfers?

display

Batch Processing Components

In the context of this article, "batch processing" means running an FTP process automatically from a Windows PC, to download a file from your AS/400. You can also execute a batch FTP process directly on the AS/400, but we're not going to explore that here. However, the technique to perform batch FTP file transfers on your AS/400 is very similar to that shown here for your Windows PC.

Since FTP is, at its heart, a console-based application (i.e., DOS), it makes sense to demonstrate how to run an FTP Batch download process using a DOS Batch file (file type *.bat). FTP, the command, has several command line switches that you can take advantage of to perform a variety of functions:

  • -v suppress display of remote server processes.
  • -n suppress auto log in upon initial connection.
  • -i turns off interactive prompting during multiple file transfers.
  • -d enables debugging.
  • -a allows the use any local interface when binding data connection.
  • -A is for "anonymous" log in.
  • -w:buffersize overrides the default transfer buffer size of 4096.
  • host = specifies the host name or IP address of the remote host to connect to.
  • -s:filename specifies a text file containing FTP commands.

It's the last command line switch in the above list, -s:filename, that we're interested in using to run FTP batch commands. By using the -s:filename command line switch, we can tell the FTP utility what server we want to connect to, what user profile we want to connect with, and what files we want to upload or download.

To use this feature, you'll need to create two files. One will be a DOS batch file (the file extension is .bat). The other is a simple text file that can end with any file extension.

An Example

Let's see how it works by looking at a real-world example.

Using Window's Notepad, create a new file and enter the following text into it:

ftp -s:C:\FTPSCRIPT.cmd 

Now save this file with any name you like, but make sure it has the .bat extension. For example, BATCHFTP.bat.

Next, create a new file and enter the following text into it:

open <I>YourIPAddress</I>
<I>AS400UserID</I>
<I>AS400Password</I>
get <I>/QSYS.LIB/QGPL.LIB/QRPGLESRC.FILE/PROOF.MBR  C:\Proof.txt</I>
quit

Now save this file with the name you entered into the .bat file above (FTPSCRIPT.cmd). The .cmd file extension could just as easily have been .txt or anything else. I use .cmd because it makes it easy for me to remember what that file was used when I see it later on.

What It Means

Here's what's going on with these files.

In the first file, the DOS batch file, the text ftp -s:C:\FTPScript.cmd is telling your PC to start an FTP session and to get the FTP runtime parameters from a file named FTPScript.cmd, stored in the C:\ drive of your PC.

The second file, which is executed by the previous file, contains the FTP runtime parameters.

The text open YourIPAddress tells FTP to open a connection to the IP address following the keyword open. Make sure you enter a valid IP address here.

AS400UserID and AS400Password is a valid AS/400 user ID and password combination. Keep in mind that this user ID and password is stored in plain text in this file, so there are some security issues involved here.

The line get /QSYS.LIB/QGPL.LIB/QRPGLESRC.FILE/PROOF.MBR C:\Proof.txt tells FTP to retrieve the source file member named PROOF from the source file QRPGLESRC, in library QGPL. This line will also cause the retrieved file to be stored in the file named Proof.txt in your C:\ directory.

Finally, the quit command tells FTP to close the connection and end the session.

When the last FTP statement is executed, control returns to your DOS Batch file.

One thing to keep in mind is that, when using FTP commands from a Windows PC, you will need to ensure that all FTP commands are entered in lowercase; otherwise they will not execute properly.

Pretty Simple

FTP is actually pretty simple to use. Take the examples shown here and modify them a bit to upload and download your own files. Pretty soon you too will become an FTP wizard!


Sponsored By
PROFOUND LOGIC SOFTWARE

Don't be left behind!

Thousands of programmers have adopted RPG-Alive, and are now able to read and understand RPG code 2 to 3 times faster.

To try RPG-Alive on your system, visit http://www.RPGAlive.com/now

"I am very happy with RPG-Alive! It's a terrific productivity booster!" says Brian Johnson of Help/Systems.

See other user testimonials at http://www.rpgalive.com/testimonials.html


THIS ISSUE
SPONSORED BY:

T.L. Ashford
SoftLanding Systems
Affirmative Computer
ASNA
Profound Logic Software
WorksRight Software


BACK ISSUES

TABLE OF CONTENTS
Plug into Sockets

Access Windows Control Panel Using VBScript

Cool Things in CODE/400: Keyboard Shortcuts

How to Interact Directly with JavaBeans from JSPs

FTP Basics: Batch Processing

The Random Number Generator API

Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Joe Hertvik
Ted Holt
David Morris
Richard Shaler

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com



Last Updated: 7/18/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.