hi im elhave and im newbie in coding
need help. i have same issue
but the telnet command, and any other command that return as question from the ssh server or ask back an input from me just don't work.
here's how i write the code
class Program
i expect the app to work like putty. read command, run command, and display the result. but seems like i cant perform it with this code.
here i type man command that will return question from server.
on putty it worked but on my application it did work.
need help. i have same issue
- i want to connect to ssh server first.
-
from that ssh server i want to telnet to other server/cisco router
but the telnet command, and any other command that return as question from the ssh server or ask back an input from me just don't work.
here's how i write the code
class Program
{
static void Main(string[] args)
{
string userName = "elhave";
string serverName = "192.168.1.1";//mysshserver
string password = "mypass";
var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(userName);
keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs) {
foreach (var prompt in eventArgs.Prompts){
if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase)) {
prompt.Response = password;
}
}
};
var passwordAuthMethod = new PasswordAuthenticationMethod(userName, password);
var connectInfo = new ConnectionInfo(serverName, userName, passwordAuthMethod, keyboardAuthMethod);
string hasil = "";
using (var serverConnection = new SshClient(connectInfo))
{
serverConnection.Connect();
var command = serverConnection.RunCommand("who");//inisialization
while (true)
{
command.Dispose();
nextcommand = Console.ReadLine();
command = serverConnection.RunCommand(nextcommand);
Console.Write(command.Result);
if (nextcommand == "break") {
break;
}
}
}
}
}
}i expect the app to work like putty. read command, run command, and display the result. but seems like i cant perform it with this code.
here i type man command that will return question from server.
on putty it worked but on my application it did work.