我想知道如何在 Visual Basic Express 中使用 C# 打开 putty。然后通过 ssh session 执行命令。
最佳答案
您可以使用 plink.exe 进行 SSH,使用 pscp.exe 进行 SCP。 https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
下载这 2 个文件,然后将它们复制到您的解决方案中。然后在“属性”下选择:如果较新则复制。
// SCP
var process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = Directory.GetCurrentDirectory() + $@"\pscp.exe";
processStartInfo.Arguments = $@"-P 22 -pw password filepath.zip root@host:/path ";
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.CreateNoWindow = true;
process.StartInfo = processStartInfo;
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine(process.ExitCode);
// SSH
process = new Process();
processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = Directory.GetCurrentDirectory() + $@"\plink.exe";
processStartInfo.Arguments = $@"-P 22 -pw password root@host command";
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.CreateNoWindow = true;
process.StartInfo = processStartInfo;
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
关于c# - 如何使用 C# 打开 Putty session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3668947/