Within my C# WPF app I am trying to access an SSH server, and script some commands. It works for simple commands such as ls
, hostname
and so on, but when I tried opening mysql
, the program just hangs and I have to End Task
. For some reason mysql
isn't counting that as a command that returns a result. My code is:
using (var client = new SshClient(hostname, username, serverPassword))
{
try
{
client.Connect();
Console.WriteLine("Command>" + sshCommand);
var run = client.CreateCommand(sshCommand);
run.Execute();
Console.WriteLine("Return Value = {0}", run.Result);
client.Disconnect();
returnedResults = run.Result;
}
catch
{
Console.WriteLine("Fail");
}
}
When I log in to the server using putty
and send the mysql command, I get this:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 113147
Server version: 5.7.21-0ubuntu0.16.04.1-log (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
I would like to script each step in changing the Mysql password, but rather than just blasting commands at the server, have a check to make sure that each command got the expected result before sending the next command.