Using FTP to Transfer Multiple Files Between Windows and the i5
October 18, 2006 Hey, Joe:
Every day, I have to transfer a variable number of files from my Windows server to my AS/400. I need to FTP all the files in the same directory and each transferable file begins with the same prefix, ABCFILE (ABCFILE.2006.09.11.2, ABCFILE.2006.09.11.3, etc). Once I get the files to the AS/400, I’d like to combine them into one file that’s simply called ABCFILE. Got any ideas?
I can tell you how to FTP multiple files at the same time, but I’m not too sure about the best method for combining them. Here’s what I’m thinking.
For transferring multiple Windows files to an AS/400, I’m assuming that you’re transferring files from the Windows server to an i5, iSeries, or AS/400 (i.e., the Windows server is functioning as the FTP client and the AS/400 is functioning as the FTP server). Since it’s a scheduled transfer, I’m also assuming that you will want to automate the transfer. If you want to see some examples of how to set up an automated Windows-to-AS/400 FTP session, check out an earlier article I wrote called Automating FTP Transfers Between OS/400 and Windows. For this example, I’m modifying the FTP code in that article for transferring a single file from Windows to an AS/400 server, changing it to send out multiple files by using the FTP MPUT command.
Here’s the FTP script that I would use to transfer your files from a Windows directory on the C: drive called HOLDOUT to a corresponding directory on the AS/400 Integrated File System (AS/400 IFS) called HOLDIN.
OPEN SERVER_NAME USER_NAME (your AS/400 FTP user_name goes here) USER_PASSWORD (the password for your AS/400 FTP user goes here) BIN CD /HOLDIN LCD C:HOLDOUT MPUT ABCFILE* QUIT
I would save this FTP script as a Windows text file called ftpinput.scr, and I would also store it in my Windows C:HOLDOUT directory. I would then create a batch file called as400ftp.bat on my Windows server that contains the following command:
ftp -i -s:C:holdoutftpinput.scr
When I execute the as400ftp.bat file either manually or through the Windows scheduler, the file will do the following things.
For an explanation of what each individual FTP command does in this script, see the Automated Windows to AS/400 transfer article. I made the following changes to my original script to meet your needs. Here’s where the differences are.
First, instead of using an FTP PUT command to transfer a single file, I used the FTP MPUT command to transfer multiple files that start with the same literal. An asterix character (*) in an MPUT command is a wildcard character that tells the server to transfer all files that begin with that literal (ABCFILE, in your case).
The second change occurs in the batch command that executes this FTP script. In the original script, I only used the -s parameter in my FTP statement to designate the name of the text file that contains the FTP commands that should be run. This time, I added the -i parameter to my FTP statement, which tells FTP to turn off any interactive messages that occur during a file transfer. If you don’t turn off the prompting when you’re sending multiple files, FTP will display the following prompt each time the MPUT statement goes to transfer another file.
Are you sure you want this file (y/n)?
Not only does this get really annoying after the first transfer, it prevents you from running this batch file in unattended mode. So using this script would allow you to easily transfer all your files to your i5 box. I tested this FTP script and batch file on a Windows XP machine, and they worked great for transferring files to an i5/OS V5R3 machine.
Unfortunately, I don’t have any techniques for combining your individually dated ABCFILEs into one larger ABCFILE on your i5 box. But I do have a suggestion. Perhaps you can combine your files before transferring them to your AS/400, and then just transfer that one ABCFILE up to your AS/400 instead of transferring multiple files. Maybe you could write a Windows program or script to combine the files. I also played a little bit with using the old DOS XCOPY command to combine the files but I had limited success. If you come up with a technique for combining your files into one file, you could easily modify your script and batch files to do the following two things:
1. You could insert the code for combining the files into the as400ftp.bat file so that it creates the single unified ABCFILE before the FTP transfer begins.
2. You could then modify your FTP code to use a PUT statement for transferring the single file instead of using the MPUT statement for transferring your multiple ABCFILE.* files. The new FTP script for the single unified transfer might look something like this:
OPEN SERVER_NAME USER_NAME (your AS/400 FTP user_name goes here) USER_PASSWORD (the password for your AS/400 FTP user goes here) BIN CD /HOLDIN LCD C:HOLDOUT PUT ABCFILE QUIT
I hope this helps. Thanks for writing.