0

I'd like to stream a .tar archive from a Windows machine using PowerShell to a Linux machine and extract the archive from the stream. PowerShell pushes archive content to stdout and plink.exe stream content to receiving command line's stdin.

I've come up with the following command.

Get-Content file.tar | & plink.exe -C -agent "remote_host" "tar xf -"

However, the tar command does recognize the file's content only partially. What I'm missing or is there a better solution for the problem?

Error message:

tar: Skipping to next header
tar: Exiting with failure status due to previous errors

1 Answers1

0

Apparently, this is an encoding issue. By default, Get-Content returns file content as an encoded string but tar expects binary stream. The solution would be to encode the binary data to a text format like Base64 and decode it. I come up to the following one-liner by its terrible slow.

[System.Convert]::ToBase64String((Get-Content -AsByteStream file.tar)) | plink.exe -C -agent "remote_host" "base64 -di | tar xvf -"

I think I'll upload files and extract those separately.