Question

  Asked: Jun 9 2008   3:08 PM GMT
  Asked by: Mlehan


AS400 FTP Batch program


FTP, AS/400, Batch

How to write FTP Batch program to run on AS400 to PT file

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



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!)



Hi,

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 :-

userid
password
cd remote_directory
lcd local_library
put local_file remote_file
(OR)
get remote_file local_file
quit

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 */
OVRDBF FILE(INPUT) TOFILE(YourLibrary/YourScript)
/* 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 */
OVRDBF FILE(OUTPUT) TOFILE(YourLibrary/LogFile)
/* Start FTP with a hostname or FTP address */
FTP RMTSYS(Your_Remote_System)
/* Remove the overrides */
DLTOVR FILE(*ALL)

This should get you up and running with scripted FTP.

Regards,

Martin Gilbert.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Networking, AS/400 and Microsoft Windows.

Looking for relevant Networking Whitepapers? Visit the SearchNetworking.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Gilly400  |   Jun 11 2008  2:23PM GMT

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.

 

Mcl  |   Jun 12 2008  5:04PM GMT

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