/// <summary> /// Binds the channel to the specified endpoint. /// </summary> /// <param name="remoteEndpoint">The endpoint to connect to.</param> /// <param name="forwardedPort">The forwarded port for which the channel is opened.</param> public void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort) { if (!IsConnected) { throw new SshException("Session is not connected."); } _forwardedPort = forwardedPort; _forwardedPort.Closing += ForwardedPort_Closing; // Try to connect to the socket try { _socket = SocketAbstraction.Connect(remoteEndpoint, ConnectionInfo.Timeout); // send channel open confirmation message SendMessage(new ChannelOpenConfirmationMessage(RemoteChannelNumber, LocalWindowSize, LocalPacketSize, LocalChannelNumber)); } catch (Exception exp) { // send channel open failure message SendMessage(new ChannelOpenFailureMessage(RemoteChannelNumber, exp.ToString(), ChannelOpenFailureMessage.ConnectFailed, "en")); throw; } var buffer = new byte[RemotePacketSize]; SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); }
/// <summary> /// Binds channel to remote host. /// </summary> public void Bind() { // Cannot bind if channel is not open if (!IsOpen) { return; } var buffer = new byte[RemotePacketSize]; SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); // even though the client has disconnected, we still want to properly close the // channel // // we'll do this in in Close() - invoked through Dispose(bool) - that way we have // a single place from which we send an SSH_MSG_CHANNEL_EOF message and wait for // the SSH_MSG_CHANNEL_CLOSE message }
/// <summary> /// Binds channel to remote host. /// </summary> public void Bind() { // Cannot bind if channel is not open if (!IsOpen) { return; } var buffer = new byte[RemotePacketSize]; SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); #if DEBUG_GERT Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Bind (after) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); #endif // DEBUG_GERT // even though the client has disconnected, we still want to properly close the // channel // // we'll do this in in Close(bool) that way we have a single place from which we // send an SSH_MSG_CHANNEL_EOF message and wait for the SSH_MSG_CHANNEL_CLOSE // message }