C# 为使用SSH.NET执行的命令提供子命令
我创建了一个简单的应用程序,它使用Renci.SshNet库更新我的Fortigate设备上的防火墙配置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
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"
有关示例代码,请参阅