C#发送一个简单的SSH命令 [英] C# send a simple SSH command

查看:1134
本文介绍了C#发送一个简单的SSH命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个年轻的学生,收到了我的功课这个星期。这是pretty困难
对我来说,因为我必须创建一个PROGRAMM,即能连接到SSH服务器
并发送COMMAMD等/ init.d /的网络重启。

I'm a young a student and received my homework for this week. It's pretty difficult for me because I have to create a programm, that is able to connect to a SSH server and send the commamd "etc/init.d/networking restart".

我要PROGRAMM在C#这个应用程序,我pretty新的给它(只是从学
一些学校的教训)。我还应该创建一个GUI。

I should programm this application in C# and I'm pretty new to it (Just have learned from some school lessons). I also should create a GUI.

我了解C#(循环,如果等)。基本

I understand the basics of C# (loop, if etc...).

我已经创建图形用户界面,菜单,按钮和一个列表框日志。
GUI = 3文本框(IP,用户名,密码)和一个按钮进行连接。

I've already created GUI, menus, buttons and a log listbox. GUI = 3 textboxes (ip, username, password) and a button to connect.

我与微软Vistual工作室编码。

I'm coding with Microsoft Vistual Studio.

我的问题是:如何建立一个SSH连接到我的服务器

My question is: How can I establish a SSH connection to my server?

推荐答案

我用 SSH.Net 在一个项目前一阵子,非常高兴。它还配备了有很多样对如何使用它的一个很好的文档。

I used SSH.Net in a project a while ago and was very happy with it. It also comes with a good documentation with lots of samples on how to use it.

有关你的情况code会是这样的。

For your case the code would be something like this.

using (var client = new SshClient("hostnameOrIp", "username", "password"))
{
    client.Connect();
    client.RunCommand("etc/init.d/networking restart");
    client.Disconnect();
}

这篇关于C#发送一个简单的SSH命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆