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"?

ceving
  • 21,900
  • 13
  • 104
  • 178

2 Answers2

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
ceving
  • 21,900
  • 13
  • 104
  • 178
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
f6a4
  • 1,684
  • 1
  • 10
  • 13
  • 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. – ceving Feb 25 '20 at 13:13