FTP refresher part I - iSeries file transfer made easy

IBM makes sending files from one system to another fairly easy. Using FTP to transfer files only requires following a few simple steps. This example assumes a transfer from one iSeries to another iSeries (a.k.a. AS/400, Series i, IBM i).

First, create a save file on the source machine. Note that the target machine must have a save file by the same name before the FTP can succeed. It is best to create the save files in QGPL so the current library will not have to be changed.

Next, save the object you wish to transfer to the new save file. Wildcards are allowed. Entire libraries can be sent with FTP.

Now the FTP can actually begin. The command is simply FTP followed by the IP address of the remote target system. If the DNS is setup in the system directory then the target system name can used instead of the IP address. The IP address is contained in single quotes. You will replace '192.168.nn.nnn' with the actual remote IP address.

This example shows saving and transferring one physical file named VENDOR from a library named APLIB. The file is saved to a save file named VENDSV then FTP'd to the remote target system. The target system can be in the same building or thousands of miles away. Note only the most basic parameters are used in this example. The purpose of this post is to explain FTP using the most simple of transfers. There are many other capabilities to be discussed in upcoming posts.

CRTSAVF FILE(QGPL/VENDSV)
SAVOBJ OBJ(VENDOR) LIB(APLIB) DEV(*SAVF) SAVF(QGPL/VENDSV)

FTP RMTSYS('nnn.nnn.nn.nnn') (logon id and password required)

230 PGMR2 logged on.
OS/400 is the remote operating system. The TCP/IP version is "V6R1M0".
250 Now using naming format "0".
257 "QGPL" is current library.
>BINARY
200 Representation type is binary IMAGE.
> put qgpl/vendsv qgpl/vendsv
>
> quit

RSTOBJ OBJ(VENDSV) SAVLIB(APLIB) DEV(*SAVF) SAVF(QGPL/VENDSV)

Note that this example uses "put" to transfer from local to remote. The same FTP can be reversed using "get" which will pull the target file to the source as long as the save files were created and the object exists in the target save file. The replace parameter can be used on the "get" or "put" to replace existing data.  This command looks odd but actually uses only a beginning parenthesis as "(REPLACE".   

Also note that when the default library is QGPL the "put" command does not need to explicitly name the target library. The target library can be changed for the ftp session by changing the "current library" using the ftp command "cd".

Unless the save file will be reused it is good housekeeping to delete the source and target save files when the FTP is finished. Note that the FTP will continue but will create a physical file instead of a save file.  Unless the save files were first created on both systems you will not be able to restore objects from the auto-created physical file (delete it, create the save file, run the FTP again).

It is a common mistake to forget to create the save file on the remote machine. A command can be added to the FTP to automatically create the save file on the target system.

QUOTE RCMD crtsavf qgpl/vendsv

Once you have the simple file transfer conquered you can move on to more advanced FTP topics.

More detail regarding the commands allowed in FTP: FTP subcommands