2017-11-28 5 views
1

で実行したコマンドにサブコマンドを提供します。は、私は私のFortigateをデバイス上でのファイアウォールの構成を更新するRenci.SshNetライブラリを使用するシンプルなアプリを作成しましたSSH.NET

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(); 

私は出力から、次を得る:

config firewall address 
fw1 # fw1 (address) # 
edit testaddress 
fw1 # Unknown action 0 fw1 # 

同じコマンドは、通常のSSH接続を介して正常に動作。

私が正しく、別 CreateCommans.Execute()を送信し、それを使用している場合だけで不思議
fw1 # config firewall address 
fw1 (address) # edit testaddress 
new entry 'testaddress' added 
fw1 (testaddress) # 

答えて

0

私はそれを正しく理解していれば、edit testaddressconfig firewall addressコマンドのサブコマンドです。

コードで別のトップレベルコマンドとして実行します。

あなたはconfig firewall addressコマンドの入力にedit testaddressサブコマンドを供給する必要があります。しかし、SSH.NETは残念なことに、CreateCommandインターフェイスの入力をサポートしていません。

あなたは(そうでない場合は、コマンドの実行を自動化するための推奨ではないアプローチものです)シェルセッションを開く必要があります。

使用SshClient.CreateShellStreamまたはSshClient.CreateShellとその入力にコマンドを送信:

"config firewall address\nedit testaddress\n" 
関連する問題