00001 using System;
00002 using System.IO;
00003 using System.Windows.Forms;
00004
00005
00006
00007
00008
00009
00010
00011 namespace Tamir.SharpSsh.jsch.examples
00012 {
00019 public class Shell
00020 {
00021 public static void Main(String[] arg)
00022 {
00023 try
00024 {
00025
00026 JSch jsch=new JSch();
00027
00028
00029 Console.WriteLine("Please enter the user and host info at the popup window...");
00030 String host = InputForm.GetUserInput
00031 ("Enter username@hostname",
00032 Environment.UserName+"@localhost");
00033 String user=host.Substring(0, host.IndexOf('@'));
00034 host=host.Substring(host.IndexOf('@')+1);
00035
00036
00037 Session session=jsch.getSession(user, host, 22);
00038
00039
00040 UserInfo ui=new MyUserInfo();
00041 session.setUserInfo(ui);
00042
00043
00044 session.connect();
00045
00046
00047 Channel channel=session.openChannel("shell");
00048
00049
00050 channel.setInputStream(Console.OpenStandardInput());
00051 channel.setOutputStream(Console.OpenStandardOutput());
00052
00053
00054 channel.connect();
00055
00056 Console.WriteLine("-- Shell channel is connected using the {0} cipher",
00057 session.getCipher());
00058
00059
00060 while(!channel.isClosed())
00061 {
00062 System.Threading.Thread.Sleep(500);
00063 }
00064
00065
00066 channel.disconnect();
00067 session.disconnect();
00068
00069 }
00070 catch(Exception e)
00071 {
00072 Console.WriteLine(e);
00073 }
00074 }
00075
00079 public class MyUserInfo : UserInfo
00080 {
00084 private String passwd;
00085
00089 public String getPassword(){ return passwd; }
00090
00094 public bool promptYesNo(String str)
00095 {
00096 return InputForm.PromptYesNo(str);
00097 }
00098
00102 public String getPassphrase(){ return null; }
00103
00107 public bool promptPassphrase(String message){ return true; }
00108
00112 public bool promptPassword(String message)
00113 {
00114 passwd=InputForm.GetUserInput(message, true);
00115 return true;
00116 }
00117
00121 public void showMessage(String message)
00122 {
00123 InputForm.ShowMessage(message);
00124 }
00125 }
00126 }
00127 }