To my knowledge FTP/SFTP if it can run will always be a success...
So if you need more, you will have to find a way of testing (not ftp command for it will be successfull...) that suits your need...
the remote server may be down at times, that time, it should not write the output of the sftp to a file, it should return error. If it is successfully connected the server, then the output should be written to a file
Code:
cat <<EOF1 > $tmp1
binary
lcd $targetDir
cd ${remoteDir}
ls
quit
EOF1
cat $tmp1
set -x
sftp6 -P 2246 -B $tmp1 --password=file://<ctl>/.gspass | tee outputfile
Now the code is writing all kind of data (either successfully connected / failed to fetch data) into the output file. It should not be the case.