SFTP-how to log individual sftp command error while executing shell script

Hi,
I have situation where i need to automate transferring 10000+ files using sftp.

while read line
do
   if [ -d "$line" ]; then
   echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt
   fi
done< files.txt
sftp -b sftpCommand.txt stu@192.168.2.1 

The above code executes each sftp command written to sftpCommand.txt.
If some error occurs while executing any sftp command,how do i log which individual sftp command(inside sftpCommand.txt) generated the error.
Please advice

so why not tar these files into a .tar.gz file first, and sftp only one time?