コード例 #1
0
ファイル: SshBot.cs プロジェクト: dusty3ntity/certpot
        public string Execute(string command)
        {
            if (!_client.IsConnected)
            {
                throw new Exception("Client is not connected");
            }
            if (!IsAuthenticated)
            {
                throw new Exception("Client is not authenticated");
            }

            var channelNum = _client.OpenSessionChannel();

            if (channelNum < 0)
            {
                throw new SshException(ErrorType.SshChannelOpeningError, _client.LastErrorText);
            }

            if (!_client.SendReqExec(channelNum, command))
            {
                throw new SshException(ErrorType.SshCommandExecutionError, _client.LastErrorText);
            }

            if (!_client.ChannelReceiveToClose(channelNum))
            {
                throw new SshException(ErrorType.SshChannelTimeout, _client.LastErrorText);
            }

            var output = _client.GetReceivedText(channelNum, Encoding);

            return(output);
        }