-
-
Notifications
You must be signed in to change notification settings - Fork 940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement -Nf and sleep #1566
Comments
We have for the ssh process:
Port forwarding in SSH.NET runs in its own thread(s), in effect it would already work in the background.
I could be wrong but I think this would mean the sleep command is ignored. We are left with local port forwarding, something like (untested, adapted from tests in https://github.com/sshnet/SSH.NET/blob/9e1ee0a380873a485a90e7c5778ed83f8dc44a15/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs): using (var client = new SshClient("host", "port", "user", "pwd"))
{
client.Connect();
using var port = new ForwardedPortLocal("127.0.0.1", 5555, "127.0.0.1", 6666);
port.Exception += (object sender, ExceptionEventArgs e) =>
{
Console.Error.WriteLine(e.Exception.ToString());
};
port.RequestReceived += (object sender, PortForwardEventArgs e) =>
{
Console.WriteLine($"Connection from {e.OriginatorHost}:{e.OriginatorPort}");
};
client.AddForwardedPort(port);
port.Start();
// Sleep here as an example, in practice store the client/port somewhere
// and close it all down when desired
Thread.Sleep(30 * 1000);
client.RemoveForwardedPort(port);
client.Disconnect();
} Hope it helps! |
Thank you for your reply |
Ok I see, I don't think there is a pre-built way to achieve that. I imagine you might need to hook into the internal code which reads from the local socket
|
First of all, thanks to ssh.net for such a handy library.
ssh.net how do I implement the following functions of a common SSH client?
ssh -NfL 5555:127.0.0.1:6666 [email protected] sleep 30
The focus is on how the functions of -Nf and sleep are implemented.
The text was updated successfully, but these errors were encountered: