/// <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(SSHConnection connection, string command, int millisecondsTimeout) { if (_status != StreamStatus.NotOpened) { throw new SCPClientInvalidStatusException(); } SCPClientChannelEventReceiver channelReceiver = new SCPClientChannelEventReceiver( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); SSHChannel channel; /* FIXME: SSH1's executing command is not implemented !! * if (connection is SSH1Connection) { * channel = ((SSH1Connection)connection).DoExecCommand(channelReceiver, command); * } * else */ if (connection is SSH2Connection) { channel = ((SSH2Connection)connection).DoExecCommand(channelReceiver, command); } else { // FIXME: //throw new ArgumentException("connection must be SSH1Connection or SSH2Connection."); throw new ArgumentException("connection must be SSH2Connection."); } _channelReceiver = channelReceiver; _channel = channel; lock (_channelReceiver.StatusChangeNotifier) { while (_channelReceiver.ChannelStatus != SCPChannelStatus.READY) { bool signaled = Monitor.Wait(_channelReceiver.StatusChangeNotifier, millisecondsTimeout); if (!signaled) { throw new SCPClientTimeoutException(); } } } lock (_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }
internal void OpenForTest(SSHChannel dummyChannel) { if (_status != StreamStatus.NotOpened) { throw new SCPClientInvalidStatusException(); } SCPClientChannelEventReceiver channelReceiver = new SCPClientChannelEventReceiver( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); _channelReceiver = channelReceiver; _channel = dummyChannel; lock (_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }
internal void OpenForTest(SSHChannel dummyChannel) { if (_status != StreamStatus.NotOpened) throw new SCPClientInvalidStatusException(); SCPClientChannelEventReceiver channelReceiver = new SCPClientChannelEventReceiver( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); _channelReceiver = channelReceiver; _channel = dummyChannel; 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(SSHConnection connection, string command, int millisecondsTimeout) { if (_status != StreamStatus.NotOpened) throw new SCPClientInvalidStatusException(); SCPClientChannelEventReceiver channelReceiver = new SCPClientChannelEventReceiver( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); SSHChannel channel; /* FIXME: SSH1's executing command is not implemented !! if (connection is SSH1Connection) { channel = ((SSH1Connection)connection).DoExecCommand(channelReceiver, command); } else */ if (connection is SSH2Connection) { channel = ((SSH2Connection)connection).DoExecCommand(channelReceiver, command); } else { // FIXME: //throw new ArgumentException("connection must be SSH1Connection or SSH2Connection."); throw new ArgumentException("connection must be SSH2Connection."); } _channelReceiver = channelReceiver; _channel = channel; lock (_channelReceiver.StatusChangeNotifier) { while (_channelReceiver.ChannelStatus != SCPChannelStatus.READY) { bool signaled = Monitor.Wait(_channelReceiver.StatusChangeNotifier, millisecondsTimeout); if (!signaled) { throw new SCPClientTimeoutException(); } } } lock(_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }