batch-fileutf-8puttybyte-order-markpsftp

PuTTY PSFTP returning error: unknown command "´╗┐cd"


HI I am running below command from my Windows server. I have got private key added so authentication wise it is fine. But when ever I am running the command getting a weird issue

psftp user@host -b FTPfile.txt

The file FTPfile.txt has only two lines.

cd /apps/scripts/batch/sln/input
put Test.txt

But I am getting error psftp: unknown command "´╗┐cd"

enter image description here

And I noticed any command given in the first line of the file returns a similar error.


Solution

  • The problem is that FTPfile.txt starts with a Unicode byte order mark (U+FEFF) encoded in UTF-8, which corresponds to the bytes 0xEF 0xBB 0xBF. psftp thinks those bytes are part of the command name. When it prints those bytes to the console as part of the error message, they're interpreted according to code page 850, which makes it look like ´╗┐.

    To fix this, you need to get rid of the BOM. How did you create FTPfile.txt? Windows text editors usually have a setting to change the encoding of a file to "ANSI" (plain ASCII would also work).