SFTP HANGS

Hi ,

we are writing a shell script to test connection of our destination servers and facing an issue if the destination server doesnt respond. we are using the following command.,

sftp -B /dev/fd/0 <host@servername> << EOF >> file.txt
quit
EOF

---------
The above command hangs for 20min and returns the following code,

warning : Connecting to <server> failed : Connection timed out.

-------------
here the exit code is zero instead of non-zero. so the script goes to success.

i have tried following options but didnt work for me.

set timeout 10
set -e timeout 10
sftp -o ConnectTimeout=10 <host@servername>

I have gone through the previous posts in this forum but didnt get any useful information.

Please help me to get proper output in case of failures.

Thanks in advance..

Cheers,
Mohan