Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为使用SSH.NET执行的命令提供子命令_C#_Ssh_Ssh.net - Fatal编程技术网

C# 为使用SSH.NET执行的命令提供子命令

C# 为使用SSH.NET执行的命令提供子命令,c#,ssh,ssh.net,C#,Ssh,Ssh.net,我创建了一个简单的应用程序,它使用Renci.SshNet库更新我的Fortigate设备上的防火墙配置 var auth = new AuthenticationMethod[] { new PasswordAuthenticationMethod(username, password) }; ConnectionInfo ConnNfo = new ConnectionInfo(server, 22, username, auth); sshclient.Connect(); s

我创建了一个简单的应用程序,它使用Renci.SshNet库更新我的Fortigate设备上的防火墙配置

var auth =
    new AuthenticationMethod[] { new PasswordAuthenticationMethod(username, password) };
ConnectionInfo ConnNfo = new ConnectionInfo(server, 22, username, auth);

sshclient.Connect();

string command;
string addressname = "testaddress";

command = "config firewall address";
output.Add(command);
output.Add(sshclient.CreateCommand(command).Execute());

command = string.Format(@"edit {0}", addressName);
output.Add(command);
output.Add(sshclient.CreateCommand(command).Execute());

sshclient.Disconnect();
我从输出中得到以下信息:

配置防火墙地址
fw1#fw1(地址)#
编辑测试地址
fw1#未知动作0 fw1#
同样的命令在正常的SSH连接上也可以正常工作

fw1#配置防火墙地址
fw1(地址)#编辑测试地址
添加新条目“testaddress”
fw1(测试地址)#

只是想知道我是否正确地使用它发送单独的
CreateCommans.Execute()

如果我理解正确,
edit testaddress
config firewall address
命令的子命令

而代码将其作为单独的顶级命令执行

您必须将
edit testaddress
子命令输入
config firewall address
命令。但是不幸的是,SSH.NET不支持使用
CreateCommand
接口提供输入

您必须打开一个shell会话(否则,不建议采用这种方法来自动执行命令)

使用
SshClient.CreateShellStream
SshClient.CreateShell
并将命令发送到其输入端:

"config firewall address\nedit testaddress\n"

有关示例代码,请参见。

如果我理解正确,
编辑测试地址
配置防火墙地址
命令的子命令

而代码将其作为单独的顶级命令执行

您必须将
edit testaddress
子命令输入
config firewall address
命令。但是不幸的是,SSH.NET不支持使用
CreateCommand
接口提供输入

您必须打开一个shell会话(否则,不建议采用这种方法来自动执行命令)

使用
SshClient.CreateShellStream
SshClient.CreateShell
并将命令发送到其输入端:

"config firewall address\nedit testaddress\n"
有关示例代码,请参阅