00001 using System;
00002 using Tamir.SharpSsh;
00003 using Tamir.SharpSsh.jsch;
00004 using System.Threading;
00005 using System.Collections;
00006 using System.IO;
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace sharpSshTest
00039 {
00043 public class sharpSshTest
00044 {
00045 const int JSCH_SHELL = 1;
00046 const int JSCH_AES = 2;
00047 const int JSCH_PUBKEY = 3;
00048 const int JSCH_SFTP = 4;
00049 const int JSCH_KEYEGEN = 5;
00050 const int JSCH_KNOWN_HOSTS = 6;
00051 const int JSCH_CHANGE_PASS = 7;
00052 const int JSCH_PORT_FWD_L = 8;
00053 const int JSCH_PORT_FWD_R = 9;
00054 const int JSCH_STREAM_FWD = 10;
00055 const int JSCH_STREAM_SUBSYSTEM = 11;
00056 const int JSCH_VIA_HTTP = 12;
00057 const int SHARP_SHELL = 13;
00058 const int SHARP_EXPECT = 14;
00059 const int SHARP_EXEC = 15;
00060 const int SHARP_TRANSFER = 16;
00061 const int EXIT = 17;
00062
00063 public static void Main()
00064 {
00065 while(true)
00066 {
00067 PrintVersoin();
00068 Console.WriteLine();
00069 Console.WriteLine("JSch Smaples:");
00070 Console.WriteLine("=============");
00071 Console.WriteLine("{0})\tShell.cs", JSCH_SHELL);
00072 Console.WriteLine("{0})\tAES.cs", JSCH_AES);
00073 Console.WriteLine("{0})\tUserAuthPublicKey.cs", JSCH_PUBKEY);
00074 Console.WriteLine("{0})\tSftp.cs", JSCH_SFTP);
00075 Console.WriteLine("{0})\tKeyGen.cs", JSCH_KEYEGEN);
00076 Console.WriteLine("{0})\tKnownHosts.cs", JSCH_KNOWN_HOSTS);
00077 Console.WriteLine("{0})\tChangePassphrase.cs", JSCH_CHANGE_PASS);
00078 Console.WriteLine("{0})\tPortForwardingL.cs", JSCH_PORT_FWD_L);
00079 Console.WriteLine("{0})\tPortForwardingR.cs", JSCH_PORT_FWD_R);
00080 Console.WriteLine("{0})\tStreamForwarding.cs", JSCH_STREAM_FWD);
00081 Console.WriteLine("{0})\tSubsystem.cs", JSCH_STREAM_SUBSYSTEM);
00082 Console.WriteLine("{0})\tViaHTTP.cs", JSCH_VIA_HTTP);
00083 Console.WriteLine();
00084 Console.WriteLine("SharpSSH Smaples:");
00085 Console.WriteLine("=================");
00086 Console.WriteLine("{0})\tSSH Shell sample", SHARP_SHELL);
00087 Console.WriteLine("{0})\tSSH Expect Sample", SHARP_EXPECT);
00088 Console.WriteLine("{0})\tSSH Exec Sample", SHARP_EXEC);
00089 Console.WriteLine("{0})\tSSH File Transfer", SHARP_TRANSFER);
00090 Console.WriteLine("{0})\tExit", EXIT);
00091 Console.WriteLine();
00092
00093 INPUT:
00094 int i=-1;
00095 Console.Write("Please enter your choice: ");
00096 try
00097 {
00098 string input = Console.ReadLine();
00099 if (input=="") return;
00100 i = int.Parse( input );
00101 Console.WriteLine();
00102 }
00103 catch
00104 {
00105 i=-1;
00106 }
00107
00108 switch(i)
00109 {
00110
00111 case JSCH_SHELL:
00112 jsch_samples.Shell.RunExample(null);
00113 break;
00114 case JSCH_AES:
00115 jsch_samples.AES.RunExample(null);;
00116 break;
00117 case JSCH_PUBKEY:
00118 jsch_samples.UserAuthPubKey.RunExample(null);
00119 break;
00120 case JSCH_SFTP:
00121 jsch_samples.Sftp.RunExample(null);
00122 break;
00123 case JSCH_KEYEGEN:
00124 jsch_samples.KeyGen.RunExample(GetArgs(new string[]{"Sig Type [rsa|dsa]", "output_keyfile", "comment"}));
00125 break;
00126 case JSCH_KNOWN_HOSTS:
00127 jsch_samples.KnownHosts.RunExample(null);
00128 break;
00129 case JSCH_CHANGE_PASS:
00130 jsch_samples.ChangePassphrase.RunExample(null);
00131 break;
00132 case JSCH_PORT_FWD_L:
00133 jsch_samples.PortForwardingL.RunExample(null);
00134 break;
00135 case JSCH_PORT_FWD_R:
00136 jsch_samples.PortForwardingR.RunExample(null);
00137 break;
00138 case JSCH_STREAM_FWD:
00139 jsch_samples.StreamForwarding.RunExample(null);
00140 break;
00141 case JSCH_STREAM_SUBSYSTEM:
00142 jsch_samples.Subsystem.RunExample(null);
00143 break;
00144 case JSCH_VIA_HTTP:
00145 jsch_samples.ViaHTTP.RunExample(null);
00146 break;
00147
00148
00149 case SHARP_SHELL:
00150 sharpssh_samples.SshShellTest.RunExample();
00151 break;
00152 case SHARP_EXPECT:
00153 sharpssh_samples.SshExpectTest.RunExample();
00154 break;
00155 case SHARP_EXEC:
00156 sharpssh_samples.SshExeTest.RunExample();
00157 break;
00158 case SHARP_TRANSFER:
00159 sharpssh_samples.SshFileTransferTest.RunExample();
00160 break;
00161 case EXIT:
00162 return;
00163 default:
00164 Console.Write("Bad input, ");
00165 goto INPUT;
00166 }
00167 }
00168 }
00169
00170 public static string[] GetArgs(string[] args)
00171 {
00172 for(int i=0; i<args.Length; i++)
00173 {
00174 Console.Write("Enter {0}: ", args[i]);
00175 args[i] = Console.ReadLine();
00176 }
00177 return args;
00178 }
00179
00180 static void PrintVersoin()
00181 {
00182 try
00183 {
00184 System.Reflection.Assembly asm
00185 = System.Reflection.Assembly.GetAssembly(typeof(Tamir.SharpSsh.SshBase));
00186 Console.WriteLine("SharpSSH-"+asm.GetName().Version);
00187 }
00188 catch
00189 {
00190 Console.WriteLine("sharpSsh v1.0");
00191 }
00192 }
00193
00194 }
00195 }