user1318369
user1318369

Reputation: 715

Handle FTP error in shell script

I am trying to do an ftp from a shell script, called by another one(parent script). the code is something like this:

ftp -inv <<EOF
open $hostname
user $username $password

binary


cd $dir
put $renamed_file

bye

EOF

when I check for the return code like:

exitStatus=$?

it always returns 0, even if the ftp fails. I am new to shell scripting and is struggling with how to resolve this. Can someone please help me out?

Thanks!

Upvotes: 0

Views: 964

Answers (1)

Charlie Dalsass
Charlie Dalsass

Reputation: 2014

You aren't going to get back the response you want if you look at the bash (or whatever shell) exit status. Bash thinks the command is working just fine - even if it's really an error. Your best bet is to use "batch mode" (your FTP program should have something like that). Capture any error output to a file or STDERR and parse to find your errors.

Upvotes: 1

Related Questions