c# - 如何使用 C# 打开 Putty session

标签 c# ssh

我想知道如何在 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/

相关文章:

c# - 将 ListView 列的宽度保存到 xml 文件

python - 带有 Cisco ASA 的 paramiko

c# - MongoDB 序列化 Dictionary<MyEnum,object>

c# - 在 Azure 上解析 html 文件

linux - 显示 Linux 启动时运行的 bash 脚本中的内容

java - J2SSH 支持的密码/Mac

linux - 无法 scp 到 Azure VM

linux - 如何通过 SSH 在远程 Linux 服务器上启动 GUI 软件?

c# - Visual Studio 2013 中的 Web 部署 - 不受信任的证书错误

c# - 如何在C#中查找char数组中的字符索引