Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell generating unknown character when echoing to file

Tags:

powershell

I am trying to echo 3 plain-text lines to a file using Powershell:

echo "#Generated" > psftp.scp
echo "put test.txt" >> psftp.scp
echo "quit" >> psftp.scp

I then use psftp.exe batch mode to run the file (executes the commands in SFTP), but psftp errors out seeing an invalid character:

psftp: unknown command " ■#"

What am I missing? I can manually type up the file in Windows Notepad and it (psftp) works. No matter what I change the first line to (#Generated) it gets this error with the block symbol in the first part.

I've tried viewing the file in NotePad++ w/ "Show All Symbols" on, but only saw CR & LF at the end of lines which is normal.

like image 508
JBurace Avatar asked Mar 15 '13 17:03

JBurace


1 Answers

Try using set/add-content instead of redirection. You might also need to set the encoding.

"#Generated" | set-content psftp.scp -Encoding Ascii
"put test.txt" | add-content psftp.scp -Encoding Ascii
"quit" | add-content psftp.scp -Encoding Ascii
like image 191
mjolinor Avatar answered Oct 02 '22 20:10

mjolinor