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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With