How to Log No Connect Error and then Exit using SFTP?

Solaris 10 9/10
BASH

using the following code snippet:

sftp $TOHOST <<RESULT
                cd /inbound/
                lcd /transfer
                put $i
                bye

I want to log no server connections and the kill the script after the log entry was made. How would I do that?

sftp $TOHOST <<RESULT
                cd /inbound/
                lcd /transfer
                put $i
                bye
RESULT

You need to close the here doc - leftmost column.
What do you mean 'kill the script' -exit early?

for i in filename1 filename2 filename3
do
sftp $TOHOST <<RESULT > logfile
                cd /inbound/
                lcd /transfer
                put $i
                bye
RESULT
   # bail out on error you decide what error message "words" to find
  grep -E -q -i '(error|fail|no connect )'  logfile  && exit 1

done

Is that what you mean?

You should use batch mode "sftp -b - $HOST <<RESULT" and check exit code $? of sftp in scripting.