Renci.SshNet.SshClient.RunCommand C# (CSharp) Method

RunCommand() public method

Creates and executes the command.
This method internally uses asynchronous calls.
CommandText property is empty. Invalid Operation - An existing channel was used to execute this command. Asynchronous operation is already in progress. Client is not connected. is null.
public RunCommand ( string commandText ) : SshCommand
commandText string The command text.
return SshCommand
        public SshCommand RunCommand(string commandText)
        {
            var cmd = CreateCommand(commandText);
            cmd.Execute();
            return cmd;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Copy from source to target
        /// </summary>
        /// <returns></returns>
        public override bool Execute(SshClient client)
        {
            bool success = false;
            try
            {
                Debug.WriteLine("ExtractCommand");

                var command1 = client.RunCommand("tar xzvf " + Target);
                var s1 = command1.Result;
                Output = s1;

                var command2 = client.RunCommand("echo $?");
                var s2 = command2.Result;
                
                var arrRsp = s2.Split(new[] {"\n"}, StringSplitOptions.None);

                if(arrRsp.Length > 0)
                    if (arrRsp[0] == "0")
                        success = true;

            } catch(Exception e)
            {
                Logger.Warn("Exception extracting archive: " +e.Message);
            }
            return success;
        }
All Usage Examples Of Renci.SshNet.SshClient::RunCommand