4

As far as I have read Powershell can not redirect input streams. Instead one has to use Get-Content to pipe the result to the target program. But this seems to create text streams.

I tried to pipe binary data to plink:

Get-Content client.zip | & 'C:\Program Files (x86)\PuTTY\plink.exe' unix nop

The target system 'unix' is a Debian with a fixed command in the authorized_keys file.

This are the first bytes of the file I tried to transfer:

00000000  50 4b 03 04 0a 00 00 00  00 00 6f 4a 59 50 c8 cb  |PK........oJYP..|

And this is what arrived on the target system:

00000000  50 4b 03 04 0d 0a 00 00  00 00 00 6f 4a 59 50 3f  |PK.........oJYP?|

'0a' gets replaced by '0d 0a'. I am not sure, but I suppose Get-Content does this.

How to pipe binary data with Powershell?

I installed already Powershell 6. I tried already the options -AsByteStream -ReadCount -Raw and I get may different funny results. But nothing gives my just an exact copy of the zip file. Where is the option "--stop-doing-anything-with-my-file"?

1
  • Did you try Get-Content -Path client.zip -Encoding Byte ? Commented Feb 25, 2020 at 11:41

2 Answers 2

1

I think I got it myself. This seems to do what I want:

Start-Process 'C:\Program Files (x86)\PuTTY\plink.exe' -ArgumentList "unix nop" -RedirectStandardInput .\client.zip -NoNewWindow -Wait
Sign up to request clarification or add additional context in comments.

Comments

0

Give this a try:

# read binary
$bytes = [System.IO.File]::ReadAllBytes('client.zip')

# pipe all Bytes to external prg
$bytes | & 'C:\Program Files (x86)\PuTTY\plink.exe' unix nop

1 Comment

This generates a text file and each line contains the decimal value of each byte of the zip file. This is one of the funny results, I mentioned in my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.