Hi Rob,
The design of FTPAPI is that each FTP action is an "API" (subprocedure)
that you call. Each procedure has a return value that indicates whether
it was successful or not -- so you don't have to scan a log file for
confirmation messages. If the transfer was successful, you get a
successful return. If not, you get a failure return value.
If you want to know the underlying error message or number, you can get
it by calling a routine that returns that information -- but it's not
really necessary if all you want to know is whether the transfer
succeeded or failed.
For example, a typically FTP script using IBM's FTP client might look
like this:
<USERID> <PASSWORD>
cd /services/edi/67891
lcd /your/local/dir
binary
put 850upload.zip
get edibatch.zip
quit
The IBM client will run all 6 lines of this script, it doesn't care if
one succeeds or fails. It'll switch to the /services/edi/67891
directory, and if that directory doesn't exist, it'll still proceed to
do the "put". If the put fails, it'll still proceed to do the "get".
If any of the command fails, FTP will still return success to the
calling application. You have to write the output to a file and try to
scan that file to find errors -- these are the problems with the IBM
client that FTPAPI aims to solve.
FTPAPI doesn't use a script file. It's a set of APIs you call from an
ILE language. (Most people call it from ILE RPG, which is what it's
written in.)
In FTPAPI, you'd do this:
handle = FTP_open( 'ftp.example.com' );
if handle = -1;
// connection to FTP server failed.
endif;
if FTP_login( handle : '<USERID>': '<PASSWORD>' ) = -1;
// couldn't log in with userid/password
// if you want to know the exact message:
errorMsg = FTP_errorMsg( handle );
endif;
if FTP_chdir( handle: 'cd /services/edi/67891' ) = -1;
// couldn't switch directory. If you want
// details as to why, you can call:
errorMsg = FTP_errorMsg( handle );
endif;
// standard IBM IFS API to change directory:
chdir('/your/local/dir');
if FTP_put( handle: '850upload.zip' ) = -1;
// put failed -- again, if you want details, you do:
errorMsg = FTP_errorMsg( handle );
endif;
if FTP_get( handle: 'edibatch.zip' ) = -1;
// put failed -- again, if you want details, you do:
errorMsg = FTP_errorMsg( handle );
endif;
FTP_quit( handle );
There's also an API (FTP_logging) that can be used to log the output
messages from the server to a log -- if you want it to -- but it's not
necessary if your only goal is to know whether your transfers succeeded
or failed.
In my opinion, IBM's FTP client is great for interactive users. But, it
has an important flaw: Despite that the FTP software itself clearly
knows when an action (an FTP subcommand) has failed, it does a very poor
job of communicating this to a calling program. All it can do is dump
the whole session to a log and let the program process this log
post-mortem. It can't even abort the session when one of the steps fails!
But, FTPAPI is designed from the ground up for program-control. The
program is constantly interacting with the FTP session, and can detect
errors at every step. You can even react to them. (Perhaps if a
directory doesn't exist, you want to create it? Or perhaps you want to
get a list of the available directories and switch to them?)
Hope that makes sense.
On 11/2/2011 10:01 AM, rob@xxxxxxxxx wrote:
I've not used it, but does this tell you what confirmation messages may be
received?
http://www.scottklement.com/ftpapi/
Rob Berendt
As an Amazon Associate we earn from qualifying purchases.