00001 using System;
00002 using System.IO;
00003 using System.Windows.Forms;
00004 using Tamir.SharpSsh.jsch;
00005
00006
00007
00008
00009
00010
00011
00012 namespace sharpSshTest.jsch_samples
00013 {
00020 public class Subsystem
00021 {
00022 public static void RunExample(String[] arg)
00023 {
00024 try
00025 {
00026
00027 JSch jsch=new JSch();
00028
00029
00030 Console.WriteLine("Please enter the user and host info at the popup window...");
00031 String host = InputForm.GetUserInput
00032 ("Enter username@hostname",
00033 Environment.UserName+"@localhost");
00034 String user=host.Substring(0, host.IndexOf('@'));
00035 host=host.Substring(host.IndexOf('@')+1);
00036
00037
00038 Session session=jsch.getSession(user, host, 22);
00039
00040
00041 UserInfo ui=new MyUserInfo();
00042 session.setUserInfo(ui);
00043
00044
00045 session.connect();
00046
00047
00048 String subsystem=InputForm.GetUserInput("Enter subsystem name", "");
00049
00050
00051 Channel channel=session.openChannel("subsystem");
00052 ((ChannelSubsystem)channel).setSubsystem(subsystem);
00053 ((ChannelSubsystem)channel).setPty(true);
00054
00055
00056
00057 channel.setInputStream(Console.OpenStandardInput());
00058 channel.setOutputStream(Console.OpenStandardOutput());
00059 ((ChannelSubsystem)channel).setErrStream(Console.OpenStandardError());
00060
00061
00062 channel.connect();
00063
00064 Console.WriteLine("-- Subsystem '"+subsystem+"' is connected using the {0} cipher",
00065 session.getCipher());
00066
00067
00068 while(!channel.isClosed())
00069 {
00070 System.Threading.Thread.Sleep(500);
00071 }
00072
00073
00074 channel.disconnect();
00075 session.disconnect();
00076
00077 }
00078 catch(Exception e)
00079 {
00080 Console.WriteLine(e);
00081 }
00082 }
00083
00087 public class MyUserInfo : UserInfo
00088 {
00092 private String passwd;
00093
00097 public String getPassword(){ return passwd; }
00098
00102 public bool promptYesNo(String str)
00103 {
00104 return InputForm.PromptYesNo(str);
00105 }
00106
00110 public String getPassphrase(){ return null; }
00111
00115 public bool promptPassphrase(String message){ return true; }
00116
00120 public bool promptPassword(String message)
00121 {
00122 passwd=InputForm.GetUserInput(message, true);
00123 return true;
00124 }
00125
00129 public void showMessage(String message)
00130 {
00131 InputForm.ShowMessage(message);
00132 }
00133 }
00134 }
00135 }