Detecting upload success/failure in a scripted command-line SFTP session?
If you batch your SFTP session, the exit status $?
will tell you if it's a failed transfer or not.
echo "put testfile1.txt" > batchfile.txt
sftp -b batchfile.txt user@host
if [[ $? != 0 ]]; then
echo "Transfer failed!"
exit 1
else
echo "Transfer complete."
fi
Edited to add: This is something we use in a production script at work, so I'm sure it's valid. We can't use scp because some of our customers are on SCO Unix.