Solved

FTP Error Control on the AS400 through Batch

Posted on 2015-01-08
4
753 Views
Last Modified: 2015-01-08
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
Comment
Question by:RjCoats
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40538147
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
 

Author Comment

by:RjCoats
ID: 40538416
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
 
LVL 35

Accepted Solution

by:
Gary Patterson earned 500 total points
ID: 40538581
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
 

Author Closing Comment

by:RjCoats
ID: 40538792
Thanks.
Rj
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question