There are so many ftp clients, and many of them do not necessarily follow the std return conventions that you must follow with some simple tests, and then code accordingly.
If you're lucky, your ftp client returns std exit codes and they are documented through man ftp (do you know about the man ftp pages?). In this case, 0 means success, and any nonzero value indicates some kind of problem, so the simplest solution is something like
if ftp user@remoteHost File remote/path ; then print -- 'sucessfully sent file' else print -u2 -- 'error sending file' fi
(I'm not quite sure that ftp user@remoteHost file remoteDir is exactly right (I do not have access to the client right now and have not used ftp in years (should I not use sftp !? ;-)) but I use the same thing in both examples to be consistent).
You probably need a little more control, so you need to take a return code.
ftp user@remoteHost File remote/path ftp_rc=$? case ${ftp_rc} in 0 ) print -- 'sucessfully sent file' ;; 1 ) print -u2 'error on userID' ; exit ${ftp_rc};; 2 ) print -u2 -- 'no localFile found' ; exit ${ftp_rc};; esac
I am not sure about the value 1 or 2, they are for illustration only. Look at your man ftp to make sure they are documented, or do a simple test where you intentionally give one error at a time for ftp to see how it reacts.
If the std error codes are not used or are inconsistent, then you need to write the ftp output and check it to determine the status, something like
ftp user@remotehost file remote/path > /tmp/ftp.tmp.$$ 2>&1 case $(< /tmp/ftp.tmp.$$ ) in sucess ) print -- 'sucessfully sent file' ;; bad_user ) print -u2 'error on userID' ; exit 1 ;; no_file ) print -u2 -- 'no localFile found' ; exit 2;; esac
Hope this helps.
source share