Redirect SFTP Output only

HI Guys,

My requiement is to redirect output and error of sftp to a file.I have gone through few solutions given in this forum and got the alternate solution but not the one i want.

Below piece of code is not working ..
$ sftp user@server<<EOF 2>&1 >temp.txt
> cd <dir>
> ls
> EOF
Warning: tcgetattr failed in ssh_rl_set_tty_modes_for_fd: fd 1: Inappropriate ioctl for device

but the below one is working..
sftp -B cmds.txt user@server 2>&1 >temp.txt
cat cmds.txt
cd <dir>
ls

Any help why the first is not working..