More .NET components

Easy-to-use API

Execute simple commands #

Executing simple commands using SSH is very easy - just connect to the server, authenticate and call RunCommand method.

CSharp

using (var ssh = new Rebex.Net.Ssh())
{
    // connect and log in
    ssh.Connect(serverName);
    ssh.Login(username, password);

    // execute a simple command
    string response = ssh.RunCommand("echo Hello world!");

    // display the response
    Console.WriteLine(response);
}

VisualBasic

Using ssh = New Rebex.Net.Ssh()
    ' connect and log in
    ssh.Connect(serverName)
    ssh.Login(username, password)

    ' execute a simple command
    Dim response As String = ssh.RunCommand("echo Hello world!")

    ' display the response
    Console.WriteLine(response)
End Using

Tip: RunCommand can only be used to execute commands that don't require any user input. To script advanced commands, use Scripting object instead.

Scripting complex commands #

To execute more commands using a single shell, or to execute commands that actually need some kind of user input, use the powerful Scripting object:

CSharp

using (var ssh = new Rebex.Net.Ssh())
{
    // connect and log in
    ssh.Connect(serverName);
    ssh.Login(username, password);

    // start a scripting session
    Scripting scripting = ssh.StartScripting();

    // automatically detect remote prompt
    scripting.DetectPrompt();

    // execute command
    scripting.SendCommand("echo Hello world!");

    // read its response
    string response = scripting.ReadUntilPrompt();

    // execute more commands
    // ...

    // display the response
    Console.WriteLine(response);
}

VisualBasic

Using ssh = New Rebex.Net.Ssh()
    ' connect and log in
    ssh.Connect(serverName)
    ssh.Login(username, password)

    ' start a scripting session
    Dim scripting As Scripting = ssh.StartScripting()

    ' automatically detect remote prompt
    scripting.DetectPrompt()

    ' execute command
    scripting.SendCommand("echo Hello world!")

    ' read its response
    Dim response As String = scripting.ReadUntilPrompt()

    ' execute more commands
    ' ...

    ' display the response
    Console.WriteLine(response)
End Using

Tip: Check out the list of Scripting features.

Tip: The Scripting object can be used to script TerminalControl or VirtualTerminal objects as well.