|
|
| 354行目: |
354行目: |
| Console.WriteLine($"予期しないエラー: {ex.Message}"); | | Console.WriteLine($"予期しないエラー: {ex.Message}"); |
| return -1; | | return -1; |
| }
| |
| }
| |
| </syntaxhighlight>
| |
| <br><br>
| |
|
| |
| == リモートPCでコマンドを実行 ==
| |
| <syntaxhighlight lang="c#">
| |
| using Renci.SshNet;
| |
|
| |
| class Program
| |
| {
| |
| static void Main(string[] args)
| |
| {
| |
| using (var client = new SshClient("<リモートPCのIPアドレス または ホスト名>",
| |
| "<リモートPCのユーザ名>",
| |
| "<リモートPCのユーザ名のパスワード>"))
| |
| {
| |
| client.Connect();
| |
|
| |
| // リモートPC上で"ls -l"コマンドを実行する
| |
| var cmd = client.RunCommand("ls -l");
| |
| Console.WriteLine(cmd.Result);
| |
|
| |
| // リモートPC上で"mkdir tmpdir"コマンドを実行する
| |
| var result = client.RunCommand("mkdir tmpdir").Execute();
| |
| Console.WriteLine("Exit code: {0}", result);
| |
| }
| |
| } | | } |
| } | | } |