问题描述
我正在使用以下方法执行SSH命令,
public async Task RequestInfoAsync(string remoteHost,string userName,string password,string cmd)
{
string plink_path = Path.Combine(Application.StartupPath,"plink.exe");
processstartinfo psi = new processstartinfo()
{
FileName = plink_path,// A const or a readonly string that points to the plink executable
Arguments = String.Format("-ssh {0}@{1} -pw {2}",userName,remoteHost,password),RedirectStandardError = true,RedirectStandardOutput = true,RedirectStandardInput = true,UseShellExecute = false,CreateNowindow = true
};
Process p = Process.Start(psi);
m_objLock = new Object();
m_blnDoRead = true;
AsyncReadFeedback(p.StandardOutput); // start the async read of stdout
AsyncReadFeedback(p.StandardError); // start the async read of stderr
StreamReader reader = p.StandardOutput;
using (StreamWriter strw = p.StandardInput)
{
await strw.WriteAsync("123456789\r");
await strw.WriteAsync("123456789\r");
await strw.WriteAsync("sys rst\r");
await strw.WriteAsync("y\r");
//await strw.WriteAsync("y\r");
//await strw.WriteAsync(cmd + "\r");
//await strw.WriteAsync("Y\r");
//}
strw.WriteLine("exit"); // send exit command at the end*/
}
MessageBox.Show("Feedback \n" + m_szFeedback);
p.WaitForExit(); // block thread until remote operations are done
}
如屏幕截图所示,有时(对于首次登录),用户必须将默认密码登录更改为SSH shell并执行命令。上面的代码在没有密码更改方案的情况下可以正常工作,但是当我尝试更改密码时,同样会失败。 如何使上述方法与SSH服务器交互并在需要时提供新密码。
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)