Programming / RPG
i talk to other servers. No, it's not a typo. This TechTip series will get your System i talking to other servers.
Back in the old days, when our server was called AS/400, there were few or even no "satellite systems" like PC servers that needed to pass and/or receive data from it. Nowadays, it's a totally different landscape: the i sits together with a broad scope of servers and devices with which it has to communicate, passing and receiving data. These interfaces are, at times, manual data imports or exports performed by operators via boring and repetitive procedures.
This TechTip series suggests a few ways to automate these procedures using FTP, ODBC, and WebSphere MQ. It doesn't intend to set a standard, just to get you thinking about your own IT landscape and interfacing needs. Hopefully, you'll find here the answers to some of your problems regarding i data import/export.
Automate Data Transfers Using FTP
Let's start with the basics: one of the most commonly used procedures to transfer data to and from the System i is FTP. I won't go into detail in this article, but there are some points worth mentioning. First of all, I'll always be referring to FTP started on a Windows PC. This may sound strange, but since Windows is (still) one of the most-used file servers and desktop OSes out there, I think it makes sense.
You can start an FTP session via a command line and use it interactively to transfer data. That's part of the boring procedure mentioned earlier. This first TechTip is on how to automate the data transfer. By using a batch file to invoke the FTP command and a script file to perform the data transfer actions, you avoid typing the same thing over and over.
FTP has some options to perform batch transfers. Let's start with option –n. This option tells the FTP command not to ask for the user name and password when the FTP session is initiated. Then, in order to run the transfer, you need to use a script file (which will contain the commands to perform) and tell the FTP where it's located. This is done using the option –s:<script file name>. Finally, you have to indicate the target system name. So your batch file should look a bit like this:
@echo Transferring file
ftp -n -s:U:ScriptsMyScript.scp MYSystemi
U:ScriptsMyScript.scp indicates the name and location of the script, and MySystemi indicates the target system name.
Of course, this is usually not that simple. You will probably need to change to the proper folder or rename the file to be transferred (or perform some other actions using DOS commands). You can use entry parameters to your batch file to achieve that. Here's another example:
@echo Transferring file %1
rename %1 myfile.txt
ftp -n -s:U:ScriptsMyScript.scp MYSystemi
This batch file will change to path H:, rename the entry parameter (%1) file name to myfile.txt, and execute the myscript.scp that resides on U:Scripts on system MySystemi.
The use of entry parameters on the batch file is especially useful because you cannot pass parameters into the script file; it's a kind of black box of commands to execute, without any flexibility.
Finally, let's see how the script file is composed.
Since we're using the –n option, which removes the prompt for user name and password, the first command of any script should always be the login:
User username password logs you into your system.
Keep in mind that doing this is a security risk: you're storing a user name and password on a text file, somewhere on a file system! You might want to create a user profile for a user who isn't allowed to sign on interactively to your System i and who has limited authorities (for instance, only has access to the IFS folder/library where the user gets or puts the files to be transferred).
After the login, you'll have to indicate the commands to be executed. These are standard FTP commands, like cd, lcd, put, get, and so on. Again, keep in mind that the script doesn't have any flexibility, so you have to use fixed directories and IFS folders/libraries on the data transfers. Here's an example of a complete script file:
user myuser mypassword
Note that FTP is case-sensitive, so be sure to type all commands in lowercase. This script, together with the batch file mentioned before, transfers the file indicated when you invoke the batch file to the IFS folder /textfiledir under the name myfile.txt. For example, imagine that your batch file is named mybatch.bat. If you type the following on a command line, you'll be transferring file h:inventory.txt to the IFS folder extfiledir under the name myfile.txt.
In the second part of this series, we will explore how to automate the transfer of a file received via email on a Lotus Domino mail server.