[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: R: [FTPAPI] Reply message from ftp_put
Hi Luciano,
What you're looking for isn't a normal part of the FTP protocol. The
text after the '226' doesn't have any defined structure -- it can
contain anything in any sequence.
So I guess you could say that you have a "custom-written extension" to
the FTP protocol. It does not make sense for FTPAPI to support that
directly. (...at least until it becomes a widely-implemented extension.)
However, you can use an exit proc to get the message. Exit proc support
was intended to make it easy to extend FTPAPI for your own uses.
After you've established your FTPAPI session (by calling FTP_open() or
FTP_conn() you can register an exit procedure for that session. Here's
an example:
FTP_exitProc( sess
: FTP_EXTLOG
: %paddr(YourProc)
: %addr(LastMsg) );
The 2nd parameter tells FTPAPI which exit point you're interested in.
In this case, FTP_EXTLOG means that a lot of the underlying FTP protocol
should be produced, one record at a time, by calling a subprocedure.
The %paddr(YourProc) part tells FTPAPI which subprocedure to call... in
this example, the subprocedure is named YourProc. It will also pass a
parameter to that subprocedure. In this cast, the parameter will be the
alphanumeric variable 'LastMsg'. (Short for "last message")
Inside FTPAPI there's a loop that occurs while communicating with the
server. Inside that loop, it's getting the response messages from the
server, and for each messagae it receives, it'll call the YourProc()
procedure. So you can think of YourProc as being called once each time
through a loop -- except that you don't code that loop. It's inside
FTPAPI itself. Hope that makes sense.
Your procedure can be very simple... something like this should work
(but I haven't tested it.)
P YourProc B
D YourProc PI
D Message 256a const
D LastMsg 256a
/free
if %subst(Message:1:4) = '226 ';
LastMsg = Message;
endif;
/end-free
P E
So, hopefully this is clear... all it does is put the contents of any
226 message into the LastMsg variable. So every single time a message
is received from the server, it checks if it's a 226... and puts it into
the LastMsg variable. Easy, right?
So your code would look something like this:
if ftp_put( sess: tofile: fromfile) = 0;
JobNo = %subst(LastMsg:11:10);
ErrMsg = *blanks;
else;
JobNo = *blanks;
ErrMsg = FTP_error();
endif;
Obviously, you can code the 'YourProc' (or whatever you decide to call
it) to capture other messages as well, or write them all to a file, or
whatever makes sense to you.
Good luck
On 12/14/2010 3:00 AM, Luciano Vigna wrote:
> Hi Scott,
>
> your words are very clear, but my exposition isn't complete; indeed, sorry,
> I miss to explain that we need to know the message 226 because the FTP
> server return a line like this:
>
> 226 JOB = TW00177920 Transfer complete...
>
> And we'll use the job number for next steps (i.e.: retrieve a report file
> named like job number release from FTP server, or write a log file for send
> history and update another file...etc)
>
> Now the problem is completely explained, thank you
>
> Luciano
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------