status code from ftp

Calvin Goodrich calvin at sequent.UUCP
Sat Feb 2 03:20:27 AEST 1991


In article <1991Jan31.222142.12395 at ux1.cso.uiuc.edu> rolf at sparc1.isgs.uiuc.edu (Rolf Wilson) writes:
>I have a routine to transfer a file to another machine
>by ftp. That part works fine. I want to delete the
>file that I sent if the transfer worked. That part 
>does not.
>
>#!/bin/sh
>ftp -n othermachine <<!
>user me
>put myfile
>quit
>!
>if [ $? -eq 0 ]
>then
>  rm myfile
>fi
>
>The $? return code is always 0, even if the other machine
>is never found. Does ftp not return a non-zero code on
>failure? Is this not "the last command executed". What
>horribly simple thing do I not understand?

i'm not a unix guru by any stretch of the imagination but i do have a pretty
good idea why your script didn't work. ftp will *always* give a return code
of 0 if you *exit* normally from ftp, whether it successfully transferred any
files or not. if something goes wrong and ftp has to exit unexpectedly then
you'll probably get something other than 0. if you want to see if the transfer
worked why not check to see if the file exists with test -f?


have a day, eh.

Calvin Goodrich   / calvin at sequent.sequent.com a\=k)4vk!%t@$+... <EOT> (beep!)

"Scotty, we need that .sig in thirty seconds or we're all dead!"
"Och, Captain! We canna do anathin'! It's still on yir other account!"

(Starfleet. It's not just an adventure, it's a job.)



More information about the Comp.unix.shell mailing list