/// <summary> /// Opens channel. /// </summary> /// <param name="connection">SSH connection object</param> /// <param name="command">Remote command</param> /// <param name="millisecondsTimeout">timeout in milliseconds</param> /// <exception cref="SCPClientInvalidStatusException">Channel has been already opened or already closed.</exception> /// <exception cref="SCPClientTimeoutException">Timeout has occurred while waiting for READY status.</exception> public void Open(ISSHConnection connection, string command, int millisecondsTimeout) { if (_status != StreamStatus.NotOpened) { throw new SCPClientInvalidStatusException(); } ISSHChannel channel = null; SCPClientChannelEventHandler eventHandler = connection.ExecCommand( (ch) => { channel = ch; return(new SCPClientChannelEventHandler( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) )); }, command ); _eventHandler = eventHandler; _channel = channel; if (!_eventHandler.WaitStatus(SCPChannelStatus.READY, millisecondsTimeout)) { throw new SCPClientTimeoutException(); } lock (_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }
/// <summary> /// Opens channel. /// </summary> /// <param name="connection">SSH connection object</param> /// <param name="command">Remote command</param> /// <param name="millisecondsTimeout">timeout in milliseconds</param> /// <exception cref="SCPClientInvalidStatusException">Channel has been already opened or already closed.</exception> /// <exception cref="SCPClientTimeoutException">Timeout has occurred while waiting for READY status.</exception> public void Open(ISSHConnection connection, string command, int millisecondsTimeout) { if (_status != StreamStatus.NotOpened) throw new SCPClientInvalidStatusException(); ISSHChannel channel = null; SCPClientChannelEventHandler eventHandler = connection.ExecCommand( (ch) => { channel = ch; return new SCPClientChannelEventHandler( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); }, command ); _eventHandler = eventHandler; _channel = channel; if (!_eventHandler.WaitStatus(SCPChannelStatus.READY, millisecondsTimeout)) { throw new SCPClientTimeoutException(); } lock(_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }