Also in this proc i am writing individual message files for each message to other directories on the external server(that bits working fine). i.e the log is just a file that contains the basic info of the messages written and a count at the top.
ray
How big is your message count likely to get? If it’s not too big, I would
Read the message file into a list.
find the list size.
write the size, and loop through the list writing the messages, to some file.
rename the file to { audit.log }
Having done this sort of thing in the past (although I favor Perl for this kind of problem, I see why it would be inconvenient here) I can tell you that you really want to avoid anything that could be a race condition when you write the audit log file. Writing to a temporary and renaming should be a minimal risk.
If I’m misunderstanding your situation, and you are just writing a local file and transferring it via ftp, then you don’t need to worry about that race condition, of course.