skip to Main Content

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)PuTTYplink.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”?

2

Answers


  1. Chosen as BEST ANSWER

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

    Start-Process 'C:Program Files (x86)PuTTYplink.exe' -ArgumentList "unix nop" -RedirectStandardInput .client.zip -NoNewWindow -Wait
    

  2. Give this a try:

    # read binary
    $bytes = [System.IO.File]::ReadAllBytes('client.zip')
    
    # pipe all Bytes to external prg
    $bytes | & 'C:Program Files (x86)PuTTYplink.exe' unix nop
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search