AS400 FTP Batch program

5 pts.
How to write FTP Batch program to run on AS400 to PT file

Answer Wiki

Thanks. We'll let you know when a new response is added.

That’s good, but I already have that portion (even creates the script “on-the-fly” to ensure file names are unique with date/time as part of the name).

Where the problem comes in is that the file being sent needs to go to a secured, FTP access denied shared drive. My approach is to FTP the file into a non-secured folder and have the execution of a .bat file to copy it onto the secured folder. I want to kick off the bat file from the same job doing the FTP. (Sarbanes Oxley making life more complex than it needs to be again!)


You’ll need to create a ‘script’ file with your FTP commands in it. You can just create a file with all the commands or if you need to do different transfers you can write a program to build the file for you. In either case you will need something along the following lines :-

cd remote_directory
lcd local_library
put local_file remote_file
get remote_file local_file

Where userid = userid on remote machine, password = password on remote machine, remote_directory = directory or library on remote machine, local_library = library on local machine, local_file = file name on local machine and remote_file = file name on remote machine.

This is basically the same order as you would do things in a manual FTP session. You may also need other commands like BIN, ASCII, etc depending on what you’re going to transfer and where you’re transferring to.

Once you have your script file in place, you will need to be able to execute it. Best to create a small CL program with the following :-

/* Override FTP input to your script file */
/* Override FTP output to a log file – if you don’t do this messages go to the screen interactively or to the qsysopr message queue from batch */
/* Start FTP with a hostname or FTP address */
FTP RMTSYS(Your_Remote_System)
/* Remove the overrides */

This should get you up and running with scripted FTP.


Martin Gilbert.

Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Gilly400
    Hi, I would suggest using a sort of "trigger file" to indicate that there is a file to be processed. You FTP your file to your non-secured folder, then FTP the trigger file to indicate that there's a file to be processed. On a machine which has access to both the secured and non-secured folders you have a job running which waits for the trigger file to appear and once the trigger file is there, moves your file from the non-secured folder to the secured folder and removes the trigger file. The use of the trigger file ensures that your job to move the file doesn't try to move the file while it's still being written to the folder. Regards, Martin Gilbert.
    23,730 pointsBadges:
  • mcl
    Looks like you have two things going on here.. 1. FTP the file to an FTP server.. 2. Copy the file from the FTP server to something no so FTP friendly.. Martin's suggestions for setting up the script is fine, and the trigger file idea is OK, but you can also try running a "remote command" in the FTP script. Try it manually first - from an iSeries command line type FTP [servername] and then log in with the proper ID and password. Then type HELP QUOTE and see what it tells you. The FTP "QUOTE" command should allow you to run a system command on a remote system - assuming the remote system supports it. You can also type HELP SERVER and get a list of commands the server supports. I believe you should be able use the QUOTE command to include a line in your script after the PUT to run a batch file to handle the copy to the "secured" directory.. Another alternative is forget the FTP altogether. Use CPYTOSTMF to drop the file onto an IFS directory and then have your "secure" system pull the file from there.. Regards Mike
    2,740 pointsBadges:
  • TLloyd
    I am trying to perform the procedure suggested by Martin Gilbert in which the script file is executed by a CL. I do not see a line of CL code that will actually call the script. Could someone please enlighten me on this. I am new to the process and need assistance with writing an FTP batch job. Thanks for your help.
    180 pointsBadges:
  • Gilly400
    Hi, The script is run by the FTP command (in combination with the OVRDBF commands). The OVRDBF to file INPUT is to tell the FTP command to use the INPUT file as the script. Regards, Martin Gilbert.
    23,730 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: