System Administration
Showing results for 
Search instead for 
Do you mean 

how to get ftp logged if transmission fails

Go to Solution
Occasional Contributor

how to get ftp logged if transmission fails

The files that we want to monitor are sent by one server to other. These files are saved to an NFS mount directory.
Is it possible to log receiving transmission? If transmission fails how to get it logged?
Acclaimed Contributor

Re: how to get ftp logged if transmission fails

Your question is somewhat confusing in that you mention ftp in the title but NFS in the body. If I can assume that you really meant FTP then it's not very difficult. You can use Perl's Net::FTP module and get error checking for free.

The attached Perl script will do all the hard work for you. All you have to do is a little shell scripting.

typeset FILENAME=myfile
typeset ERRLOG=/var/tmp/ftperrs
typeset -i STAT=0 -h remhost -l mickey -p secret -B -d /aaa/bbb -t 3 ${FILENAME}
if [[ ${STAT} -ne 0 ]]
echo "Transfer of ${FILENAME} failed; status ${STAT}." >> ${ERRLOG}
exit ${STAT}

That would login to remhost as user mickey, password "secret", set binary mode, cd to /aaa/bbb and transfer "myfile". It would automatically retry up to 3 times. If the command returns 0 all is well otherwise log the error. Just like real ftp, you can create a .netrc entry so that the password does not have to be used. Invoke as -h for full usage.

If it ain't broke, I can fix that.