Providing subcommands to a command (sudo/su) executed with SSH.NET SshClient.CreateShellStream

Just write the “commands” to the StreamWriter. writer.WriteLine(“sudo su – wwabc11”); writer.WriteLine(“whoami”); // etc See also C# send Ctrl+Y over SSH.NET. Though note that using CreateShellStream (“shell” channel) is not the correct way to automate a commands execution. You should use CreateCommand/RunCommand (“exec” channel). Though SSH.NET limited API to the “exec” channel does not support … Read more

Connection to MySQL from .NET using SSH.NET Library

Most of the code below is self explanatory. Still I have put the needful comments. I was able to connect to the MySql database with the code below. I had used SSH library from here and MySql connector for .NET. using(var client = new SshClient(“ssh server id”, “sshuser”, “sshpassword”)) // establishing ssh connection to server … Read more

Providing input/subcommands to a command (cli) executed with SSH.NET SshClient.RunCommand

AFAIK, cli is a kind of a shell/interactive program. So I assume you have tried to do something like: client.RunCommand(“cli”); client.RunCommand(“some cli subcommand”); That’s wrong. cli will keep waiting for subcommands and never exit, until you explicitly close it with a respective command (like exit). And after it exits, the server will try to execute … Read more

How to run commands on SSH server in C#?

You could try https://github.com/sshnet/SSH.NET. With this you wouldn’t need putty or a window at all. You can get the responses too. It would look sth. like this. SshClient sshclient = new SshClient(“172.0.0.1”, userName, password); sshclient.Connect(); SshCommand sc= sshclient .CreateCommand(“Your Commands here”); sc.Execute(); string answer = sc.Result; Edit: Another approach would be to use a shellstream. … Read more

techhipbettruvabetnorabahisbahis forumu