1828220 Members
2063 Online
109975 Solutions
New Discussion

Re: FTP error handling

 
SOLVED
Go to solution
Patricia Davey
New Member

FTP error handling

Hi,
Using OpenVMS V7.3-2 I have a batch program that creates and submits an ftp process to copy a file from server a to server b using tcpip. Occasionally, the ftp fails due to network error, access denied, etc. When there is an error like:
%TCPIP-E-FTP_NETERR, I/O error on network device
-TCPIP-W-EAI_AGAIN, temporary failure

The user wants to get emailed to notify him that the FTP has not completed successfully.My problem is that the status code that the FTP process returns to the parent program is the same whether the FTP is successful or not - This is the status code %X00030001. How can I code this so that the parent program will execute an error routine if there is an FTP error?

Thanks !
15 REPLIES 15
Craig A
Valued Contributor
Solution

Re: FTP error handling

Patricia

One way would be to look for a successful string and then alert if it isn't present.

If you do a PUT and the link breaks then the file will be left overhanging.

Try:

PUT PAT.DAT PAT.TMP
RENAME PAT.TMP PAT.DAT

then check for the success string for a RENAME. For my local system the string is:

250 File renamed to

So:

$ SEARCH "250 File"," renamed to " /MATCH=AND
$ STATUS := '$STATUS'
$ IF STATUS .EQ. %X08D78053
$ THEN
$ SUCCESS = 0
$ ELSE
$ SUCCESS = 1
$ ENDIF

Is a pretty simple way of determining whether the FTP was successful.

HTH

Craig
Patricia Davey
New Member

Re: FTP error handling

Hi Craig,

Thanks for your quick response. My understanding of your solution is that I search the batch log file for a successful FTP command like 250 CWD command successful or 226 Transfer complete and then write error code if the commands are not there. My problem is that the ftp process is within the batch command procedure and there is only one log file produced.

For example in batch1.com here are the following commands:
$set on
$@pdftp_script.com server1 "lcd ud1:[temp], cd """""\dwfiles""""",mput *.*,dir"
$ftp_exit_status=$status
$if ftp_exit_status .eqs. ??? goto x

(Last two lines I want to work but don't). Batch1.com writes to batch1.log so I cannot search it while it it being written to.
labadie_1
Honored Contributor

Re: FTP error handling

Hi

Another idea is to use a command file, say a.com, containing the ftp commands, the syntax ftp host /user /password, and test $status

$ type a.com
put zzz.txt
quit

and issue a
$ def/user sys$input a.com
$ ftp host/user=my_user/pass=my_pass
$ sh symb $status

I get
$STATUS == "%X17649AAA"
(which translates to
%TCPIP-E-FTP_LOGREJ, login request rejected
after a
$ set message sys$message:tcpip$msg.exe
$ exit %X17649AAA )
when I put a bad password,
and
$STATUS == %X17649A01
(which translates to
%TCPIP-S-FTP_EXIT, exit per user command )
with a succesfull FTP.

So, if you don't get this last status, there is a problem.
Fekko Stubbe
Valued Contributor

Re: FTP error handling

You could try

$@pdftp_script.com/out=tmpfile server1 "lcd ud1:[temp], cd """""\dwfiles""""",mput *.*,dir"

And then you can search tmpfile for the string you want. If you want the log of the script in the total log, you can use
$type tempfile

Don't forget to delete the tempfile after the search/type.


Fekko
Steven Schweda
Honored Contributor

Re: FTP error handling

> Using OpenVMS V7.3-2 [...]

TCPIP SHOW VERSION

> I have a batch program that creates and
> submits an ftp process to copy a file from
> server a to server b using tcpip.

Is this job running on "server a" or "server
b" or somewhere else?

> [...] My problem is that the ftp process is
> within the batch command procedure [...]

So change that?

HELP SPAWN
Craig A
Valued Contributor

Re: FTP error handling

Also, bear in mind that FTP can "hang". I got round this by spawninga subprocess for the actual FTP and then monitoring it using F$GETJPI (off the top of my head I think I checked Direct I/O - if it hadn't increased after 10 rounds of 30 seconds then consider the FTP job hung), kill it and re-schedule.

Craig

Hoff
Honored Contributor

Re: FTP error handling

ftp is a festering pile of insecure ugly, and a construct and protocol best shoved out the airlock at your first available opportunity.

Consider using the FTSO package on the OpenVMS Freeware. It's free, it's a little buggy and slightly arcane, it'll likely never appear on OpenVMS I64, but it'll do what you want here, and way more.

(Not to imply that FTSO is any more secure, nor any less ugly than ftp.)

http://decuslib.com/decus/freewarev70/ftso/

For DECnet, use the FTSV variant:

http://decuslib.com/decus/freewarev70/ftsv/
Craig A
Valued Contributor

Re: FTP error handling

>ftp is a festering pile of insecure ugly, >and a construct and protocol best shoved >out the airlock at your first available >opportunity.

Get off that fence, Hoff! :-)

Craig
John Gillings
Honored Contributor

Re: FTP error handling

Patricia,

Tracking errors can be tricky... first, a misconception:

> Batch1.com writes to batch1.log so I
> cannot search it while it it being
> written to.

Yes you can! Log files are shared read, and you can control the disk flush interval. Use SET OUTPUT_RATE to set the flush timer to some known value. After some event you're interested, wait that long, then SEARCH the log file.

$ PIPE TYPE/TAIL= BATCH1.LOG | SEARCH SYS$PIPE "whatever"

(I posted some code recently that uses this idea. See last few posts in http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1444100 ).

But that's not the best way to keep track of errors. FTP should be returning $STATUS correctly, you just have to save it somewhere.

Find the actual FTP command:

$ FTP... whatever
$ ftpstatus=$STATUS

if it's in a lower level procedure you can return it in a global symbol:

$ ftpstatus==$STATUS

or as the completion status for the procedure, like this:

$ EXIT F$INTEGER(ftpstatus).OR.%X10000000

(the OR will stop the EXIT command from displaying the error message).

If it's in a subprocess or pipe segment, return it via the job logical name table

to "send":

$ DEFINE/JOB/NOLOG FTPSTATUS "''ftpstatus'"

to "receive":

$ ftpstatus=F$INTEGER(F$TRNLNM("FTPSTATUS"))

If you can't get a useable status from the FTP command, try using COPY/FTP instead.
A crucible of informative mistakes
RBrown_1
Trusted Contributor

Re: FTP error handling

Instead of using the generated ftp command file, use COPY/FTP and then you can check the status of individual operations.
Craig A
Valued Contributor

Re: FTP error handling

RBrown

Be careful with COPY/FTP.

If the link breaks mid-copy you could be left with a file fragmen on the remote server. Not helpful if there is an automated process on the remote node to process incoming files.

Craig
Peter Barkas
Regular Advisor

Re: FTP error handling

"Also, bear in mind that FTP can "hang"."

Isn't this resolved by turning on FTP keepalive?

$ def/sys/exec tcpip$ftp_keepalive 1
Craig A
Valued Contributor

Re: FTP error handling

Peter

I had inconsistent results when fiddling with that. So decided on my workaround. Necessity is the mother of invention!

Craig
jjinva
Advisor

Re: FTP error handling

Maybe an over simplification but how about using the On error command. Right before the FTP you can use:

$ on error then goto error_end:

Where Error_end is:

$ error_end:
$ !
$ mail/subj="FTP Job Failed!" NL: "SMTP%user@company.com"

Patricia Davey
New Member

Re: FTP error handling

Thanks to all of you for your suggestions. I have used a combination of Craig A's and Fekko Stubbe's responses to sort out my FTP issue and it is working very well.