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

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

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

sftp can pass flags directly to ssh so you may want to investigate that. Also there is a -v flag you can use which increasing logging (also passed directly to ssh ).