How to set file transfer in binary mode in SFTP using Expect?

The below is my script.

/usr/bin/expect<<EOD
        spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST
        expect "sftp>"
        expect "password:"
        set timout 15
        send "$password\r"
        expect "sftp>"
        send "lcd $remotedir\r"
        expect "sftp>"
        send "cd $lob\r"
        expect "sftp>"
        send "mkdir $newdir\r"
        expect "sftp>"
        send "cd $newdir\r"
        expect "sftp>"
        send "mput *.dat\r"
        expect "sftp>"
        log_file -noappend ls.out
        send  "ls\n"
        expect "sftp>"
        send "bye\r"

In binary transfers (default i.e., what you have), data is transferred to the server byte-by-byte with no data
conversion. The \r makes the file a windows text file, which is your problem. I think. Depends on how the system that receives the file looks at it. Some systems use the file extension.

I'm not sure about this one line: log_file -noappend ls.out which seems to be non-standard sftp and/or non-standard shell.