SSH Linux commands
Remote execute Linux command lines on the robot controller.
SSH is a protocol that allows you to remotly execute Linux command lines robot controller.
This feature is made possible because an embedded Linux is running in the robot.
You can also use this library to remote manipulate files over SSH, see the SFTP documentation.
Remote execute Linux commands
SSH features are not enabled by default when connecting to the robot. You must enable it and specify the Linux user name and password. If these credentials are not specified, the user is "ur" and the password "easybot".
To do this set the Ssh.EnableSSh property in ConnectParameters class.
Please then refer to the API reference below which lists all the available file and folder handling features.
If you wish to manipulate files outside of any instance of the UR object, you can create an instance of class Ssh.SshClient which has the same functions.
The RunCommand method allows you to synchronously execute a command and wait for its response.
Default credentials
-
Default user on a real robot :
root -
Default user on the simulator :
ur -
Default password :
easybot
Enable SSH access
You may need to enable access on the robot. In Polyscope, navigate to Settings > Security > Secure Shell and ensure that SSH access is enabled.
using UnderAutomation.UniversalRobots;using UnderAutomation.UniversalRobots.Ssh.Tools;class SshRunCommand{static void Main(string[] args){// Create a new robot instancevar robot = new UR();// Setup connection to th robotvar param = new ConnectParameters();param.IP = "192.168.0.1";// Enable SSHparam.Ssh.EnableSftp = true;// If not specified, credentials are "ur" with password "easybot"param.Ssh.Username = "John";param.Ssh.Password = "!!PASS!!";// Connect to the robotrobot.Connect(param);// Create a execute the commandSshCommand command = robot.Ssh.RunCommand("echo Hello > /home/ur/Desktop/NewFile.txt");// Get resultstring result = command.Result; // console outputint exitStatus = command.ExitStatus; // exit status}}
Remote start a shell
The creation of a shell allows to maintain a session and to have a working directory, like in a terminal. The method CreateShellStream allows to create a shell. It takes as parameter a window size. An event DataReceived is raised when the console outputs text.
using UnderAutomation.UniversalRobots;using UnderAutomation.UniversalRobots.Ssh.Tools;using UnderAutomation.UniversalRobots.Ssh.Tools.Common;class SshCreateShell{static void Main(string[] args){// Create a new robot instancevar robot = new UR();// Setup connection to th robotvar param = new ConnectParameters();param.IP = "192.168.0.1";// Enable SSHparam.Ssh.EnableSsh = true;// If not specified, credentials are "ur" with password "easybot"param.Ssh.Username = "John";param.Ssh.Password = "!!PASS!!";// Connect to the robotrobot.Connect(param);// Create a shell and specify its sizeShellStream shell = robot.Ssh.CreateShellStream("My super app", 40, 100, 40, 100, 1000);shell.DataReceived += Shell_DataReceived;shell.WriteLine("ping 192.168.0.10");}private static void Shell_DataReceived(object sender, ShellDataEventArgs e){// New shell line from the robotstring dataReceived = e.Line;}}
Try it with the Windows example

API reference
Provides a client connection to SSH server
| Member | Type | Description |
|---|---|---|
SshClient() Constructor | ||
Connect(string, string, string, int) Method | void | Connects to the robot
|
Contains operation for working with SSH Shell.
| Member | Type | Description |
|---|---|---|
CanRead Property read only | bool | Gets a value indicating whether the current stream supports reading. |
CanSeek Property read only | bool | Gets a value indicating whether the current stream supports seeking. |
CanWrite Property read only | bool | Gets a value indicating whether the current stream supports writing. |
DataAvailable Property read only | bool | Gets a value that indicates whether data is available on the ShellStream to be read. |
Length Property read only | long | Gets the length in bytes of the stream. |
Position Property | long | Gets or sets the position within the current stream. |
DataReceived Event | EventHandler<ShellDataEventArgs> | Occurs when data was received. |
ErrorOccurred Event | EventHandler<ExceptionEventArgs> | Occurs when an error occurred. |
BeginExpect(AsyncCallback, object, params ExpectAction[]) Method | IAsyncResult | Begins the expect.
|
BeginExpect(AsyncCallback, params ExpectAction[]) Method | IAsyncResult | Begins the expect.
|
BeginExpect(TimeSpan, AsyncCallback, object, params ExpectAction[]) Method | IAsyncResult | Begins the expect.
|
BeginExpect(params ExpectAction[]) Method | IAsyncResult | Begins the expect.
|
Dispose(bool) Method | void | Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
|
EndExpect(IAsyncResult) Method | string | Ends the execute.
|
Expect(string) Method | string | Expects the expression specified by text.
|
Expect(string, TimeSpan) Method | string | Expects the expression specified by text.
|
Expect(Regex) Method | string | Expects the expression specified by regular expression.
|
Expect(Regex, TimeSpan) Method | string | Expects the expression specified by regular expression.
|
Expect(TimeSpan, params ExpectAction[]) Method | void | Expects the specified expression and performs action when one is found.
|
Expect(params ExpectAction[]) Method | void | Expects the specified expression and performs action when one is found.
|
Flush() Method | void | Clears all buffers for this stream and causes any buffered data to be written to the underlying device. |
Read() Method | string | Reads text available in the shell. |
Read(byte[], int, int) Method | int | Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
|
ReadLine() Method | string | Reads the line from the shell. If line is not available it will block the execution and will wait for new line. |
ReadLine(TimeSpan) Method | string | Reads a line from the shell. If line is not available it will block the execution and will wait for new line.
|
Seek(long, SeekOrigin) Method | long | This method is not supported.
|
SetLength(long) Method | void | This method is not supported.
|
Write(byte[], int, int) Method | void | Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
|
Write(string) Method | void | Writes the specified text to the shell.
|
WriteLine(string) Method | void | Writes the line to the shell.
|
Represents SSH command that can be executed.
| Member | Type | Description |
|---|---|---|
CommandText Property read only | string | Gets the command text. |
CommandTimeout Property | TimeSpan | Gets or sets the command timeout. |
Error Property read only | string | Gets the command execution error. |
ExitStatus Property read only | int | Gets the command exit status. |
ExtendedOutputStream Property read only | Stream | Gets the extended output stream. |
OutputStream Property read only | Stream | Gets the output stream. |
Result Property read only | string | Gets the command execution result. |
BeginExecute() Method | IAsyncResult | Begins an asynchronous command execution. |
BeginExecute(AsyncCallback) Method | IAsyncResult | Begins an asynchronous command execution.
|
BeginExecute(AsyncCallback, object) Method | IAsyncResult | Begins an asynchronous command execution.
|
BeginExecute(string, AsyncCallback, object) Method | IAsyncResult | Begins an asynchronous command execution.
|
Dispose() Method | void | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
Dispose(bool) Method | void | Releases unmanaged and - optionally - managed resources
|
EndExecute(IAsyncResult) Method | string | Waits for the pending asynchronous command execution to complete.
|
Execute() Method | string | Executes command specified by CommandText property. |
Execute(string) Method | string | Executes the specified command text.
|
~SshCommand() Method | void | Releases unmanaged resources and performs other cleanup operations before the SshCommand is reclaimed by garbage collection. |
Each method also exists in an asynchronous version, with the same name followed by Async and an optional cancellation token.