Transferring a binary file between two machines when Clipboard is the only interface
Question / Problem:
A file needs to be transferred from one machine to the other. Neither a file transfer option nor the internet/FTP are available. But the Windows clipboard is available as an interface (RDPClip.exe). When the file to be transferred is Text, the solution is easy: Open Notepad on machine 1, load file, mark/copy all, open Notepad on machine 2, paste, save file, done. But what if the file is binary (e.g a DLL or an EXE or a ZIP)?
Answer / Solution:
Use the according Powershell commands to convert the Binary to String and back, so Notepad and copy/paste can be used for the transfer.
Enter How to here:
-
On machine 1:
$to = Get-Content -Encoding Byte -Path c:\temp\example.exe /* the .exe is loaded as bytestream into the Variable $to -
[convert]::ToBase64String($to) > c:\temp\example.txt /* the string is written into a Textfile
-
notepad c:\temp\example.txt, mark all, copy all, start notepad on machine 2, paste all, save file to c:\temp\example.txt
-
on machine 2:
$fro =[convert]::FromBase64String((get-content -path c:\temp\example.txt)) /* the way back: the Textfile gets converted into a Variable -
[io.file]::WriteAllBytes("c:\temp\example.exe", $fro) /* all bytes from the variable are being written into the .exe
Applies to:
Product | Version |
---|---|
all | all |