Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1017
  • Last Modified:

FTP Error Control on the AS400 through Batch

Hi.
I have an iSeries V7.R1 and a CL batch job that uses FTP and an FTP command file.
The CL calls a series of programs that create files for me to hook up via FTP and PUT and GET data files.
This CL is run in the job scheduler at night and in the day without human help.

Occasionally the FTP wont connect but the FTP command file keeps on going, only to display in the log as "there must be a connection first" before putting or getting, etc.

My question is, is there a way to monitor an error within the FTP command file, possibly stop the process and pass that problem back to the CL that called the FTP command file so we can attempt a re-do, without all for the processes failing and having to manually correct it.

Its not a problem that happens very often, but when it does, we have to manually recreate data to send back up there on the next run.

Thanks in Advance.
Rj
0
RjCoats
Asked:
RjCoats
  • 2
  • 2
1 Solution
 
Gary PattersonVP Technology / Senior Consultant Commented:
Assuming you're using a method like this:

http://www.itjungle.com/tfh/tfh070703-story04.html

you'd just write code to parses the FTP session output file and look for errors in the log  based on what you find, you'd take the appropriate action.

In recent years, I've been using the Expect scripting language to automate sftp sessions (most places are getting away from ftp for external transfers due to security requirements), but the same technique can be applied to FTP and any other interactive unix-style utility, for that matter.  Expect has very sophisticated capabilities for scripting interactive utilities, and you can find extensive documentation and examples online.  Scott Klement has a brief example in this presentation:

http://www.scottklement.com/presentations/Setting%20up%20and%20Scripting%20the%20OpenSSH,%20SFTP%20and%20SCP%20Utilities%20on%20IBM%20i.pdf
0
 
RjCoatsAuthor Commented:
Gotcha. Thanks Gary. Was hoping there was some sort of method in the FTP command to abort and send a message code to the CL that called it if something went wrong. Its usually that it just doesn't connect with the remote server.
 In the past research I had not been able to find one, but thought I'd ask.

Basically I have a CL that creates a file then ftp's it to a site, where they pick it up.
if it doesn't connect, the program just keeps on trucking as if it did, dishing out log messages "you must first open a connection" . I have a log that tells me what its doing, but nothing reading that log to find out. Doing that manually when we realize there was a transfer problem.
Thanks again.
Rj
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Ultimately, the native FTP client is designed to be an interactive tool.  It isn't designed as a program-to-program interface, so it doesn't do the things we expect an automated interface to do with regard to error handling.

This is one of those problems that has a lot of solutions.  

As I mentioned before, one common solution is to just parse the log.  It isn't a "pretty" solution, and it is "after the fact", but it works.

You can also use a third-party FTP tool like Trailblazer ZMod - it has the ability to do connection-detection and return a CPF message.  Automates FTP in CL very nicely.

You can also use a tool like Scott Klement's FTPAPI that provides a better batch interface to FTP, and specifically addresses the problem you are having detecting errors when doing batch file transfers.  

http://www.scottklement.com/ftpapi/

Personally, I like general-purpose tools, and Expect scripting is just that.  It is a cross-platform tool (IBM i, IBM mainframe, AIX, Linux, Unix, Windows, etc) that helps with automation of interactive command-line style tools like FTP, sFTP, Telnet, etc.  There is a bit of learning curve, but you can get it to do a lot of neat stuff (and you can find sample script online).  You can also use it to set an environment variable or set a return code that your CL program can detect to determine status.  If you decide to explore this route, let me know and I'd be happy to provide you with some example scripts.
0
 
RjCoatsAuthor Commented:
Thanks.
Rj
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now