00001 using System;
00002 using System.Windows.Forms;
00003
00004
00005
00006
00007
00008
00009
00010 namespace Tamir.SharpSsh.jsch.examples
00011 {
00020 public class PortForwardingL
00021 {
00022 public static void Main(String[] arg)
00023 {
00024 int port;
00025
00026 try
00027 {
00028
00029 JSch jsch=new JSch();
00030
00031
00032 Console.WriteLine("Please enter the user and host info at the popup window...");
00033 String host = InputForm.GetUserInput
00034 ("Enter username@hostname",
00035 Environment.UserName+"@localhost");
00036 String user=host.Substring(0, host.IndexOf('@'));
00037 host=host.Substring(host.IndexOf('@')+1);
00038
00039
00040 Session session=jsch.getSession(user, host, 22);
00041
00042
00043 String foo = InputForm.GetUserInput("Enter -L port:host:hostport","port:host:hostport");
00044 int lport=int.Parse(foo.Substring(0, foo.IndexOf(':')));
00045 foo=foo.Substring(foo.IndexOf(':')+1);
00046 String rhost=foo.Substring(0, foo.IndexOf(':'));
00047 int rport=int.Parse(foo.Substring(foo.IndexOf(':')+1));
00048
00049
00050 UserInfo ui=new MyUserInfo();
00051 session.setUserInfo(ui);
00052 session.connect();
00053
00054 Console.WriteLine("localhost:"+lport+" -> "+rhost+":"+rport);
00055
00056
00057 session.setPortForwardingL(lport, rhost, rport);
00058 }
00059 catch(Exception e)
00060 {
00061 Console.WriteLine(e);
00062 }
00063 }
00064
00068 public class MyUserInfo : UserInfo
00069 {
00073 private String passwd;
00074
00078 public String getPassword(){ return passwd; }
00079
00083 public bool promptYesNo(String str)
00084 {
00085 return InputForm.PromptYesNo(str);
00086 }
00087
00091 public String getPassphrase(){ return null; }
00092
00096 public bool promptPassphrase(String message){ return true; }
00097
00101 public bool promptPassword(String message)
00102 {
00103 passwd=InputForm.GetUserInput(message, true);
00104 return true;
00105 }
00106
00110 public void showMessage(String message)
00111 {
00112 InputForm.ShowMessage(message);
00113 }
00114 }
00115 }
00116 }