00001 using System;
00002 using System.Collections;
00003 using Tamir.SharpSsh;
00004
00005 namespace sharpSshTest.sharpssh_samples
00006 {
00010 public class SshExeTest
00011 {
00012 public static void RunExample()
00013 {
00014 try
00015 {
00016 SshConnectionInfo input = Util.GetInput();
00017 SshExec exec = new SshExec(input.Host, input.User);
00018 if(input.Pass != null) exec.Password = input.Pass;
00019 if(input.IdentityFile != null) exec.AddIdentityFile( input.IdentityFile );
00020
00021 Console.Write("Connecting...");
00022 exec.Connect();
00023 Console.WriteLine("OK");
00024 while(true)
00025 {
00026 Console.Write("Enter a command to execute ['Enter' to cancel]: ");
00027 string command = Console.ReadLine();
00028 if(command=="")break;
00029 string output = exec.RunCommand(command);
00030 Console.WriteLine(output);
00031 }
00032 Console.Write("Disconnecting...");
00033 exec.Close();
00034 Console.WriteLine("OK");
00035 }
00036 catch(Exception e)
00037 {
00038 Console.WriteLine(e.Message);
00039 }
00040 }
00041 }
00042 }