You can wait for the prompt to type username and password by using ShellStream
and Expect
method.
using (SshClient client = new SshClient("10.10.10.41", 22, username, password))
{
client.Connect();
ShellStream shellStream = client.CreateShellStream(string.Empty, 0, 0, 0, 0, 0);
shellStream.Expect("Please create a local administrator account."); // probably can be omitted
shellStream.Expect("Username:"); // Expect has more parameters
shellStream.WriteLine(newUsername);
shellStream.Expect("Password:"); // prompt to type password
shellStream.WriteLine(newPassword);
client.Disconnect();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…