/// <summary> /// Open a session channel and configure the required parameters. /// </summary> /// <param name="windowsize"></param> /// <param name="packetlen"></param> /// <param name="listener"></param> /// <returns></returns> public SSHSession OpenSessionChannel(int windowsize, int packetlen, ChannelStateListener listener) { VerifyConnection(true); SSH2Session session = new SSH2Session(windowsize, packetlen, this); session.StateChange += listener; connection.OpenChannel(session, null); if (context.X11Display != null) { #if DEBUG System.Diagnostics.Trace.WriteLine("Requesting X Forwarding for " + context.X11Display); #endif System.String display = context.X11Display; String hostname = "localhost"; String tmp; int screen = 0; int idx = display.IndexOf(':'); if (idx != -1) { hostname = display.Substring(0, idx); tmp = display.Substring(idx + 1); } else { tmp = display; } idx = tmp.IndexOf("."); if (idx != -1) { screen = Int32.Parse(tmp.Substring(idx + 1)); tmp = tmp.Substring(0, idx); } byte[] x11FakeCookie = context.X11AuthenticationCookie; System.Text.StringBuilder cookieBuf = new System.Text.StringBuilder(); for (int i = 0; i < 16; i++) { System.String b = System.Convert.ToString(x11FakeCookie[i], 16); if (b.Length == 1) { b = "0" + b; } cookieBuf.Append(b); } if (session.RequestX11Forwarding(false, "MIT-MAGIC-COOKIE-1", cookieBuf.ToString(), screen)) { isXForwarding = true; } } return(session); }
/// <summary> /// Open a TCPIP forwarding channel to the remote computer. If successful the remote computer will open /// a socket to the host/port specified and return a channel which can be used to forward TCPIP data /// from the local computer to the remotley connected socket.<br/> /// <br/> /// It should be noted that this is a low level API method and it does not connect the transport to the /// channel. Future versions of this API will provide a ForwardingClient to automate transfer between /// the tunnel and a local listening Socket. /// </summary> /// <param name="hostname"></param> /// <param name="port"></param> /// <param name="listeningAddress"></param> /// <param name="listeningPort"></param> /// <param name="originatingHost"></param> /// <param name="originatingPort"></param> /// <param name="transport"></param> /// <param name="listener"></param> /// <returns></returns> public SSHTunnel OpenForwardingChannel(System.String hostname, int port, System.String listeningAddress, int listeningPort, System.String originatingHost, int originatingPort, Object transport, ChannelStateListener listener) { try { SSH2ForwardingChannel tunnel = new SSH2ForwardingChannel( SSH2ForwardingChannel.LOCAL_FORWARDING_CHANNEL, 131072, 32768, hostname, port, listeningAddress, listeningPort, originatingHost, originatingPort, transport, true); ByteBuffer request = new ByteBuffer(); request.WriteString(hostname); request.WriteUINT32(port); request.WriteString(originatingHost); request.WriteUINT32(originatingPort); if (listener != null) { tunnel.StateChange += listener; } OpenChannel(tunnel, request.ToByteArray()); tunnel.ResumeWindow(); return(tunnel); } catch (System.IO.IOException ex) { throw new SSHException(ex.Message, SSHException.INTERNAL_ERROR); } }
/// <summary> /// Open a session channel and attach the given state listening delegate. /// </summary> /// <param name="listener"></param> /// <returns></returns> public SSHSession OpenSessionChannel(ChannelStateListener listener) { VerifyConnection(true); return(OpenSessionChannel(32768, 32768, listener)); }