I am expierencing an issue with a powershell script which doesn't work whereas dotnet application with the same commands works. I believe the problem is related to encoding, I think in powershell the encoding is different which causes some non-transparent problems with a byte-object-marker or decoding/encoding itself.
A little bit background, I am using proxy command in ssh to automate some steps of setting up a tunnel. I have a working prototype that is using a small dotnet based executable that forwards stdin and stdout to a tcp socket. However preferable I'd like to use vanilla powershell script if possible.
The information that should be forwarded over stdin/stdout should be preserved as-is without any encoding conversion, and when I use a dotnet application it fully works, but when I use the powershell script with equavelent code ssh basically reports sometimes the packet sizes are different / unexpected big.
Anybody have any idea what type of call I could do to reset powershell to not encode stdin/stdout but map the data 1:1?
Host XXYYZZWW
User server
HostName 127.0.0.1
Port 2222
StrictHostKeyChecking no
NumberOfPasswordPrompts 0
PasswordAuthentication no
BatchMode yes
IdentityFile ~/.ssh/id_rsa
ProxyCommand powershell -File D:/Workspaces/liquid/maintenancw/rustdesk-ssh.ps1 -LocalPort 2222 -RemotePort 22 -RemoteHost 127.0.0.1 -RustdeskId XXYYZZWW
param ($RustdeskId, $IdentityFile, $User, $LocalPort, $RemotePort, $RemoteHost, $RemoteUser)
$def = @"
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System;
public class MyClass {
public void Run() {
var tcpClient = new System.Net.Sockets.TcpClient("localhost", 2222);
tcpClient.NoDelay = true;
var tcpStream = tcpClient.GetStream();
var stdin = System.Console.OpenStandardInput();
var stdout = System.Console.OpenStandardOutput();
System.Threading.Tasks.Task.WaitAll(stdin.CopyToAsync(tcpStream, 1024), tcpStream.CopyToAsync(stdout, 1024));
}
}
"@
Add-Type -TypeDefinition $def
$obj = New-Object MyClass
$obj.Run()