UnderAutomation
質問ですか?

[email protected]

お問い合わせ
UnderAutomation
⌘Q
This page is only available in English.

SFTP file handling

Manipulate robot files and folders (like *.urp programs) : download, upload, rename, delete, move, enumerates...

  • Connect to the robot via SFTP
  • Default credentials
  • Enable SSH access
  • Try it with the Windows example
  • API Reference

SFTP (Secure File Transfer Protocol) is a protocol on SSH that allows to create, read, update, delete (CRUD) files and folders on the robot controller.

This feature is made possible because an embedded Linux is running in the robot.

You can also use this library to execute Linux command lines remotely, see the SSH documentation.

Connect to the robot via SFTP

SFTP 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.EnableSftp 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.SftpClient which has the same functions.

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;
class Sftp
{
static void Main(string[] args)
{
// Create a new robot instance
var robot = new UR();
// Setup connection to th robot
var param = new ConnectParameters();
param.IP = "192.168.0.1";
// Enable SFTP
param.Ssh.EnableSftp = true;
// If not specified, credentials are "ur" with password "easybot"
param.Ssh.Username = "John";
param.Ssh.Password = "!!PASS!!";
// Connect to the robot
robot.Connect(param);
// Download a file from the robot
robot.Sftp.DownloadFile("/home/ur/ursim-current/programs/my-program.urp", @"C:\temp\my-program.urp");
// send file my-program.urp to the robot
robot.Sftp.UploadFile(@"C:\temp\my-program.urp", "/home/ur/ursim-current/programs/my-program.urp");
// Rename a file
robot.Sftp.RenameFile("/home/ur/ursim-current/programs/my-program.urp", "/home/ur/ursim-current/programs/my-program2.urp");
// Enumerate a directory
foreach (var element in robot.Sftp.ListDirectory("/home/ur/ursim-current/programs/"))
{
Console.WriteLine($"Name : {element.Name}");
Console.WriteLine($"IsDirectory : {element.IsDirectory}");
Console.WriteLine($"Bytes : {element.Length}");
Console.WriteLine($"Write time : {element.LastWriteTimeUtc}");
}
// Delete file or directory
robot.Sftp.Delete("/home/ur/ursim-current/programs/my-program.urp");
// Write in file
robot.Sftp.WriteAllText("/home/ur/ursim-current/programs/file.txt", "Hello !");
}
}

Try it with the Windows example

SFTP

API Reference

Class
SftpClientinherits SftpClientBase
C#Python
MemberTypeDescription
SftpClient()
Constructor
Connect(string, string, string, int)
Method
void
Connects to the robot
  • ip : Robot IP address
  • username : Robot linux username (default username is ur for simulator and root for real robot)
  • password : Associated user password (default is easybot)
  • port : SFTP port
Class
SftpClientBaseinherits URServiceBase
C#Python

Implementation of the SSH File Transfer Protocol (SFTP) over SSH for transfering files to the robot controller

MemberTypeDescription
SftpClientBase()
Constructor
BufferSize
Property
uint
Gets or sets the maximum size of the buffer in bytes.
Connected
Property
read only
bool
Gets a value indicating if this client is connected to the robot
OperationTimeout
Property
TimeSpan
Gets or sets the operation timeout.
ProtocolVersion
Property
read only
int
Gets sftp protocol version.
WorkingDirectory
Property
read only
string
Gets remote working directory.
AppendAllLines(string, string[])
Method
void
Appends lines to a file, creating the file if it does not already exist.
  • path : The file to append the lines to. The file is created if it does not already exist.
  • contents : The lines to append to the file.
AppendAllLines(string, string[], Encoding)
Method
void
Appends lines to a file by using a specified encoding, creating the file if it does not already exist.
  • path : The file to append the lines to. The file is created if it does not already exist.
  • contents : The lines to append to the file.
  • encoding : The character encoding to use.
AppendAllText(string, string)
Method
void
Appends the specified string to the file, creating the file if it does not already exist.
  • path : The file to append the specified string to.
  • contents : The string to append to the file.
AppendAllText(string, string, Encoding)
Method
void
Appends the specified string to the file, creating the file if it does not already exist.
  • path : The file to append the specified string to.
  • contents : The string to append to the file.
  • encoding : The character encoding to use.
AppendText(string)
Method
StreamWriter
Creates a StreamWriter that appends UTF-8 encoded text to the specified file, creating the file if it does not already exist.
  • path : The path to the file to append to.
AppendText(string, Encoding)
Method
StreamWriter
Creates a StreamWriter that appends text to a file using the specified encoding, creating the file if it does not already exist.
  • path : The path to the file to append to.
  • encoding : The character encoding to use.
BeginDownloadFile(string, Stream)
Method
IAsyncResult
Begins an asynchronous file downloading into the stream.
  • path : The path.
  • output : The output.
BeginDownloadFile(string, Stream, AsyncCallback)
Method
IAsyncResult
Begins an asynchronous file downloading into the stream.
  • path : The path.
  • output : The output.
  • asyncCallback : The method to be called when the asynchronous write operation is completed.
BeginDownloadFile(string, Stream, AsyncCallback, object, Action<ulong>)
Method
IAsyncResult
Begins an asynchronous file downloading into the stream.
  • path : The path.
  • output : The output.
  • asyncCallback : The method to be called when the asynchronous write operation is completed.
  • state : A user-provided object that distinguishes this particular asynchronous write request from other requests.
  • downloadCallback : The download callback.
BeginListDirectory(string, AsyncCallback, object, Action<int>)
Method
IAsyncResult
Begins an asynchronous operation of retrieving list of files in remote directory.
  • path : The path.
  • asyncCallback : The method to be called when the asynchronous write operation is completed.
  • state : A user-provided object that distinguishes this particular asynchronous write request from other requests.
  • listCallback : The list callback.
BeginSynchronizeDirectories(string, string, string, AsyncCallback, object)
Method
IAsyncResult
Begins the synchronize directories.
  • sourcePath : The source path.
  • destinationPath : The destination path.
  • searchPattern : The search pattern.
  • asyncCallback : The async callback.
  • state : The state.
BeginUploadFile(Stream, string)
Method
IAsyncResult
Begins an asynchronous uploading the stream into remote file.
  • input : Data input stream.
  • path : Remote file path.
BeginUploadFile(Stream, string, AsyncCallback)
Method
IAsyncResult
Begins an asynchronous uploading the stream into remote file.
  • input : Data input stream.
  • path : Remote file path.
  • asyncCallback : The method to be called when the asynchronous write operation is completed.
BeginUploadFile(Stream, string, AsyncCallback, object, Action<ulong>)
Method
IAsyncResult
Begins an asynchronous uploading the stream into remote file.
  • input : Data input stream.
  • path : Remote file path.
  • asyncCallback : The method to be called when the asynchronous write operation is completed.
  • state : A user-provided object that distinguishes this particular asynchronous write request from other requests.
  • uploadCallback : The upload callback.
BeginUploadFile(Stream, string, bool, AsyncCallback, object, Action<ulong>)
Method
IAsyncResult
Begins an asynchronous uploading the stream into remote file.
  • input : Data input stream.
  • path : Remote file path.
  • canOverride : Specified whether an existing file can be overwritten.
  • asyncCallback : The method to be called when the asynchronous write operation is completed.
  • state : A user-provided object that distinguishes this particular asynchronous write request from other requests.
  • uploadCallback : The upload callback.
ChangeDirectory(string)
Method
void
Changes remote directory to path.
  • path : New directory path.
ChangePermissions(string, short)
Method
void
Changes permissions of file(s) to specified mode.
  • path : File(s) path, may match multiple files.
  • mode : The mode.
ConnectInternal(string, int, string, string)
Method
void
Create(string)
Method
SftpFileStream
Creates or overwrites a file in the specified path.
  • path : The path and name of the file to create.
Create(string, int)
Method
SftpFileStream
Creates or overwrites the specified file.
  • path : The path and name of the file to create.
  • bufferSize : The maximum number of bytes buffered for reads and writes to the file.
CreateDirectory(string)
Method
void
Creates remote directory specified by path.
  • path : Directory path to create.
CreateText(string)
Method
StreamWriter
Creates or opens a file for writing UTF-8 encoded text.
  • path : The file to be opened for writing.
CreateText(string, Encoding)
Method
StreamWriter
Creates or opens a file for writing text using the specified encoding.
  • path : The file to be opened for writing.
  • encoding : The character encoding to use.
Delete(string)
Method
void
Deletes the specified file or directory.
  • path : The name of the file or directory to be deleted. Wildcard characters are not supported.
DeleteDirectory(string)
Method
void
Deletes remote directory specified by path.
  • path : Directory to be deleted path.
DeleteFile(string)
Method
void
Deletes remote file specified by path.
  • path : File to be deleted path.
Disconnect()
Method
void
DownloadFile(string, Stream, Action<ulong>)
Method
void
Downloads remote file specified by the path into the stream.
  • path : File to download.
  • output : Stream to write the file into.
  • downloadCallback : The download callback.
DownloadFile(string, string, Action<ulong>)
Method
void
Downloads remote file specified by the path into the stream.
  • path : File to download.
  • localPath : Local file to download
  • downloadCallback : The download callback.
EndDownloadFile(IAsyncResult)
Method
void
Ends an asynchronous file downloading into the stream.
  • asyncResult : The pending asynchronous SFTP request.
EndListDirectory(IAsyncResult)
Method
SftpFile[]
Ends an asynchronous operation of retrieving list of files in remote directory.
  • asyncResult : The pending asynchronous SFTP request.
EndSynchronizeDirectories(IAsyncResult)
Method
FileInfo[]
Ends the synchronize directories.
  • asyncResult : The async result.
EndUploadFile(IAsyncResult)
Method
void
Ends an asynchronous uploading the stream into remote file.
  • asyncResult : The pending asynchronous SFTP request.
EnumerateInstallations()
Method
string[]
Enumerates installations with .installation extension. It searches recursively installations in "/programs" if it exists, or "/home/ur/ursim-current/programs" for simulator
EnumeratePrograms()
Method
string[]
Enumerates programs with .urp extension. It searches recursively programs in "/programs" if it exists, or "/home/ur/ursim-current/programs" for simulator
Exists(string)
Method
bool
Checks whether file or directory exists;
  • path : The path.
Get(string)
Method
SftpFile
Gets reference to remote file or directory.
  • path : The path.
GetAttributes(string)
Method
SftpFileAttributes
Gets the SftpFileAttributes of the file on the path.
  • path : The path to the file.
GetLastAccessTime(string)
Method
DateTime
Returns the date and time the specified file or directory was last accessed.
  • path : The file or directory for which to obtain access date and time information.
GetLastAccessTimeUtc(string)
Method
DateTime
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.
  • path : The file or directory for which to obtain access date and time information.
GetLastWriteTime(string)
Method
DateTime
Returns the date and time the specified file or directory was last written to.
  • path : The file or directory for which to obtain write date and time information.
GetLastWriteTimeUtc(string)
Method
DateTime
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.
  • path : The file or directory for which to obtain write date and time information.
GetStatus(string)
Method
SftpFileSytemInformation
Gets status using [email protected] request.
  • path : The path.
ListDirectory(string, Action<int>)
Method
SftpFile[]
Retrieves list of files in remote directory.
  • path : The path.
  • listCallback : The list callback.
Open(string, FileMode)
Method
SftpFileStream
Opens a SftpFileStream on the specified path with read/write access.
  • path : The file to open.
  • mode : A FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.
Open(string, FileMode, FileAccess)
Method
SftpFileStream
Opens a SftpFileStream on the specified path, with the specified mode and access.
  • path : The file to open.
  • mode : A FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.
  • access : A FileAccess value that specifies the operations that can be performed on the file.
OpenRead(string)
Method
SftpFileStream
Opens an existing file for reading.
  • path : The file to be opened for reading.
OpenText(string)
Method
StreamReader
Opens an existing UTF-8 encoded text file for reading.
  • path : The file to be opened for reading.
OpenWrite(string)
Method
SftpFileStream
Opens a file for writing.
  • path : The file to be opened for writing.
ReadAllBytes(string)
Method
byte[]
Opens a binary file, reads the contents of the file into a byte array, and closes the file.
  • path : The file to open for reading.
ReadAllLines(string)
Method
string[]
Opens a text file, reads all lines of the file using UTF-8 encoding, and closes the file.
  • path : The file to open for reading.
ReadAllLines(string, Encoding)
Method
string[]
Opens a file, reads all lines of the file with the specified encoding, and closes the file.
  • path : The file to open for reading.
  • encoding : The encoding applied to the contents of the file.
ReadAllText(string)
Method
string
Opens a text file, reads all lines of the file with the UTF-8 encoding, and closes the file.
  • path : The file to open for reading.
ReadAllText(string, Encoding)
Method
string
Opens a file, reads all lines of the file with the specified encoding, and closes the file.
  • path : The file to open for reading.
  • encoding : The encoding applied to the contents of the file.
ReadLines(string)
Method
string[]
Reads the lines of a file with the UTF-8 encoding.
  • path : The file to read.
ReadLines(string, Encoding)
Method
string[]
Read the lines of a file that has a specified encoding.
  • path : The file to read.
  • encoding : The encoding that is applied to the contents of the file.
RenameFile(string, string)
Method
void
Renames remote file from old path to new path.
  • oldPath : Path to the old file location.
  • newPath : Path to the new file location.
RenameFile(string, string, bool)
Method
void
Renames remote file from old path to new path.
  • oldPath : Path to the old file location.
  • newPath : Path to the new file location.
  • isPosix : if set to true then perform a posix rename.
SetAttributes(string, SftpFileAttributes)
Method
void
Sets the specified SftpFileAttributes of the file on the specified path.
  • path : The path to the file.
  • fileAttributes : The desired SftpFileAttributes.
SymbolicLink(string, string)
Method
void
Creates a symbolic link from old path to new path.
  • path : The old path.
  • linkPath : The new path.
SynchronizeDirectories(string, string, string)
Method
FileInfo[]
Synchronizes the directories.
  • sourcePath : The source path.
  • destinationPath : The destination path.
  • searchPattern : The search pattern.
UploadFile(Stream, string, Action<ulong>)
Method
void
Uploads stream into remote file.
  • input : Data input stream.
  • path : Remote file path.
  • uploadCallback : The upload callback.
UploadFile(Stream, string, bool, Action<ulong>)
Method
void
Uploads stream into remote file.
  • input : Data input stream.
  • path : Remote file path.
  • canOverride : if set to true then existing file will be overwritten.
  • uploadCallback : The upload callback.
UploadFile(string, string, Action<ulong>)
Method
void
Uploads file into remote file.
  • localPath : Local file to read and transfer.
  • path : Remote file path.
  • uploadCallback : The upload callback.
WriteAllBytes(string, byte[])
Method
void
Writes the specified byte array to the specified file, and closes the file.
  • path : The file to write to.
  • bytes : The bytes to write to the file.
WriteAllLines(string, string[])
Method
void
Writes a collection of strings to the file using the UTF-8 encoding, and closes the file.
  • path : The file to write to.
  • contents : The lines to write to the file.
WriteAllText(string, string)
Method
void
Writes the specified string to the file using the UTF-8 encoding, and closes the file.
  • path : The file to write to.
  • contents : The string to write to the file.
WriteAllText(string, string, Encoding)
Method
void
Writes the specified string to the file using the specified encoding, and closes the file.
  • path : The file to write to.
  • contents : The string to write to the file.
  • encoding : The encoding to apply to the string.
Class
SftpFile
C#Python

Represents SFTP file information

MemberTypeDescription
Attributes
Property
read only
SftpFileAttributes
Gets the file attributes.
FullName
Property
read only
string
Gets the full path of the directory or file.
GroupCanExecute
Property
bool
Gets or sets a value indicating whether the group members can execute this file.
GroupCanRead
Property
bool
Gets or sets a value indicating whether the group members can read from this file.
GroupCanWrite
Property
bool
Gets or sets a value indicating whether the group members can write into this file.
GroupId
Property
int
Gets or sets file group id.
IsBlockDevice
Property
read only
bool
Gets a value indicating whether file represents a block device.
IsCharacterDevice
Property
read only
bool
Gets a value indicating whether file represents a character device.
IsDirectory
Property
read only
bool
Gets a value indicating whether file represents a directory.
IsNamedPipe
Property
read only
bool
Gets a value indicating whether file represents a named pipe.
IsRegularFile
Property
read only
bool
Gets a value indicating whether file represents a regular file.
IsSocket
Property
read only
bool
Gets a value indicating whether file represents a socket.
IsSymbolicLink
Property
read only
bool
Gets a value indicating whether file represents a symbolic link.
LastAccessTime
Property
DateTime
Gets or sets the time the current file or directory was last accessed.
LastAccessTimeUtc
Property
DateTime
Gets or sets the time, in coordinated universal time (UTC), the current file or directory was last accessed.
LastWriteTime
Property
DateTime
Gets or sets the time when the current file or directory was last written to.
LastWriteTimeUtc
Property
DateTime
Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to.
Length
Property
read only
long
Gets or sets the size, in bytes, of the current file.
Name
Property
read only
string
For files, gets the name of the file. For directories, gets the name of the last directory in the hierarchy if a hierarchy exists. Otherwise, the Name property gets the name of the directory.
OthersCanExecute
Property
bool
Gets or sets a value indicating whether the others can execute this file.
OthersCanRead
Property
bool
Gets or sets a value indicating whether the others can read from this file.
OthersCanWrite
Property
bool
Gets or sets a value indicating whether the others can write into this file.
OwnerCanExecute
Property
bool
Gets or sets a value indicating whether the owner can execute this file.
OwnerCanRead
Property
bool
Gets or sets a value indicating whether the owner can read from this file.
OwnerCanWrite
Property
bool
Gets or sets a value indicating whether the owner can write into this file.
UserId
Property
int
Gets or sets file user id.
Delete()
Method
void
Permanently deletes a file on remote machine.
MoveTo(string)
Method
void
Moves a specified file to a new location on remote machine, providing the option to specify a new file name.
  • destFileName : The path to move the file to, which can specify a different file name.
SetPermissions(short)
Method
void
Sets file permissions.
  • mode : The mode.
ToString()
Method
string
Returns a string that represents this instance.
UpdateStatus()
Method
void
Updates file status on the server.
Class
SftpFileAttributes
C#Python

Contains SFTP file attributes.

MemberTypeDescription
Extensions
Property
read only
IDictionary<string,string>
Gets or sets the extensions.
GroupCanExecute
Property
bool
Gets a value indicating whether the group members can execute this file.
GroupCanRead
Property
bool
Gets a value indicating whether the group members can read from this file.
GroupCanWrite
Property
bool
Gets a value indicating whether the group members can write into this file.
GroupId
Property
int
Gets or sets file group id.
IsBlockDevice
Property
read only
bool
Gets a value indicating whether file represents a block device.
IsCharacterDevice
Property
read only
bool
Gets a value indicating whether file represents a character device.
IsDirectory
Property
read only
bool
Gets a value indicating whether file represents a directory.
IsNamedPipe
Property
read only
bool
Gets a value indicating whether file represents a named pipe.
IsRegularFile
Property
read only
bool
Gets a value indicating whether file represents a regular file.
IsSocket
Property
read only
bool
Gets a value indicating whether file represents a socket.
IsSymbolicLink
Property
read only
bool
Gets a value indicating whether file represents a symbolic link.
LastAccessTime
Property
DateTime
Gets or sets the local time the current file or directory was last accessed.
LastAccessTimeUtc
Property
DateTime
Gets or sets the UTC time the current file or directory was last accessed.
LastWriteTime
Property
DateTime
Gets or sets the local time when the current file or directory was last written to.
LastWriteTimeUtc
Property
DateTime
Gets or sets the UTC time when the current file or directory was last written to.
OthersCanExecute
Property
bool
Gets a value indicating whether the others can execute this file.
OthersCanRead
Property
bool
Gets a value indicating whether the others can read from this file.
OthersCanWrite
Property
bool
Gets a value indicating whether the others can write into this file.
OwnerCanExecute
Property
bool
Gets a value indicating whether the owner can execute this file.
OwnerCanRead
Property
bool
Gets a value indicating whether the owner can read from this file.
OwnerCanWrite
Property
bool
Gets a value indicating whether the owner can write into this file.
Size
Property
long
Gets or sets the size, in bytes, of the current file.
UserId
Property
int
Gets or sets file user id.
GetBytes()
Method
byte[]
Returns a byte array representing the current SftpFileAttributes.
SetPermissions(short)
Method
void
Sets the permissions.
  • mode : The mode.

Universal Robots、Fanuc、Yaskawa、ABB、Staubli ロボットを .NET、Python、LabVIEW、または Matlab アプリケーションに簡単に統合

UnderAutomation
お問い合わせLegal

© All rights reserved.