我想知道如何在 Visual Basic Express 中使用 C# 打开 putty。然后通过 ssh 会话执行命令。
您可以使用 plink.exe 进行 SSH,使用 pscp.exe 进行 SCP。https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html https://www.chiark.greenend.org.uk/%7Esgtatham/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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)