我使用c#中的plink連接到Linux服務器並運行一些程序。 C#控制檯程序和plink.exe都在同一臺Windows機器上。如何對c#中plink的緩存關鍵問題做出回答yes
問題是,當我第一次連接到Linux服務器時,plink問我是否要接受並存儲來自Linux服務器的SSH密鑰。我總是想對此做出迴應,因爲所有的服務器都在我的局域網中,並且沒有安全問題。
我正在使用c#過程類型,將正確的參數傳遞給plink,重定向輸出並開始。現在問題是當plink提示時,process.StandardOutput.ReadToEnd();掛起,我無法確定我是否被plink提示接受密鑰或實際登錄到Linux服務器。
string output = string.Empty;
string error = string.Empty;
string arguments = @" -ssh -pw password [email protected] ./Install_xxx.bin";
using (Process process = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "plink";
psi.Arguments = arguments;
psi.ErrorDialog = false;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
process.StartInfo = psi;
process.Start();
output = process.StandardOutput.ReadToEnd();
error = process.StandardError.ReadToEnd();
}
感謝
謝謝...我決定使用異步方法。 – danze 2011-03-18 19:47:01