ftp exit code

2007-12-25 10:50:00

Thanks all ,,,, huge response. Too many to list.

ORIGINAL POST

> We have a rather critical in-house app that

> uses ftp inside a script.

>

> Are there any graceful ways to test that

> the ftp was successful? Here is a code sample:

>

> ftp -n -v slooppy <<++EOF++

> user Lname Pword

> bye

> ++EOF++

> echo "$?"

>

> In this example, sloopy is a bogus name yet

> the $? is always 0. Obviously, an error

> inside ftp does not cause the exit code of

> ftp itself to be non-zero.

> Thus, if the real machine/network is down, or

> the ftp fails, we have no way of knowing about

> the failure.

SUMMARY

The solutions fell into 5 categories.

Category Votes Description

------------------------------------------------------------------

stdout 6 Save stdout into a file and parse it for errors

ftp 6 Check that you can "get" the file after you've "put" it

expect 5 Use the expect scripting language to check "responses"

rcp/scp 1 Use rcp or scp instead of ftp. I'm not sure what scp is.

                    I'm guessing it's a better rcp (maybe SecureCopy)

ping 1 Check the hosts availablility with ping or try

                    connecting to port 21 with nc (netcat).

perl 1 Someone suggested a perl script called "mirror" that seems

                    to have exit code checking.

The solution that fit best and easiest into my existing

script was the "stdout" solution.

Here is a csh example sent by Thad MacMillan

ftp -n classfeeds.advance.net << FTP_EOF > .status

user xxxxxxxx xxxxxxxx

binary

put $file

FTP_EOF

if [ -s .status ]; then

        cat > .failed << MAIL_MESSAGE_EOF.

Thanks very much for all your advice.

-Mark


--
Mark Belanger (mjb@ltx.com) | LTX Corporation
LTX Park at University Ave | Voice : (781) 467-5021
Westwood, MA 02090-2306, USA | Fax : (781) 329-6880

Comments

Got something to say?

You must be logged in to post a comment.