Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "PTP/designs/remote/API"

< PTP‎ | designs‎ | remote
(Remote Services Plugins)
(Usage Examples)
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page provides a brief overview of the PTP remote services API. The purpose of this API is to provide a programming interface to remote services that is agnostic to the actual remote services implementation. Current implementation supported are RSE and Remote Tools (light-weight ssh layer that is part of PTP). It also provides an implementation for the local system (where Eclipse is run).
+
This page provides a brief overview of the remote services API. The purpose of this API is to provide a programming interface to remote services that is agnostic to the actual remote services implementation. Currently the only implementation supported is JSch, but support for RSE and Remote Tools (light-weight ssh layer that is part of PTP) are available in PTP. An implementation for the local system (where Eclipse is run) is also provided.
 +
 
 +
The API is generic enough so that it is possible to use it for all remote *or* local operations. This is useful for situations where both a remote and local mode should be provided, but the programmer wants to avoid two separate code paths.
  
 
== Types of Services ==
 
== Types of Services ==
Line 9: Line 11:
 
The remote services are divided into two plugins. These plugins should have no dependencies other than the platform.
 
The remote services are divided into two plugins. These plugins should have no dependencies other than the platform.
  
* <code>org.eclipse.ptp.remote.core</code>
+
* <code>org.eclipse.remote.core</code>
* <code>org.eclipse.ptp.remote.ui</code>
+
* <code>org.eclipse.remote.ui</code>
  
Remote service providers are adapted to these interfaces using a set of adapter plugins. There are currently two implementations. These plugins are dependent on the remote services implementations, but are optional for the remote services API. The API will automatically detect the installed plugins.
+
Remote service implementations provide the actual remote functionality using a particular remote protocol. These are supplied as a set of adapter plugins. There is currently one implementation using JSch.
  
# RSE
+
* <code>org.eclipse.remote.jsch.core</code>
** <code>org.eclipse.ptp.remote.rse.core</code>
+
* <code>org.eclipse.remote.jsch.ui</code>
** <code>org.eclipse.ptp.remote.rse.ui</code>
+
  
# Remote Tools
+
These plugins are dependent on the remote services implementations, but are optional for the remote services API. The API will automatically detect the installed plugins.
** <code>org.eclipse.ptp.remote.remotetools.core</code>
+
** <code>org.eclipse.ptp.remote.remotetools.ui</code>
+
  
== API ==
+
== Core Services ==
  
=== PTPRemoteCorePlugin ===
+
The remote services package provides a set of core services for manipulating remote resources. These are described in more detail below.
  
The <code>PTPRemoteCorePlugin</code> provides the main entry point for accessing remote services. Typically usage is to call getAllRemoteServices() to retrieve all the known service providers and allow the user to select from the list (or auto select). Once an IRemoteServices object has been obtained, it can be used to access all the remaining remote functionality.
+
=== RemoteServices class ===
  
; <code>public IRemoteServices[] getAllRemoteServices()</code> : Retrieve all the known remote service providers.
+
The <code>RemoteServices</code> class provides the main entry point for accessing remote services. Typically usage is to call getRemoteServices() passing either an ID or a URI to retrieve the remote services implementation. The ID can be obtained using the UI services described below. Once an IRemoteServices object has been obtained, it can be used to access all the remaining remote functionality.
 +
 
 +
; <code>public IRemoteServices getRemoteServices(String id)</code> : Retrieve the remote service provider associated with id.
  
 
; <code>public IRemoteServices getRemoteServices(URI uri)</code> : Retrieve the remote service provider associated with a URI.
 
; <code>public IRemoteServices getRemoteServices(URI uri)</code> : Retrieve the remote service provider associated with a URI.
  
; <code>public IRemoteConnection getConnection(URI uri)</code> : Retrieve a remote connection associated with a URI.
+
; <code>public IRemoteConnection getLocalServices()</code> : Retrieve the local services.
 
+
=== PTPRemoteUIPlugin ===
+
 
+
The <code> PTPRemoteUIPlugin </code> provides the main entry point for accessing UI functionality for remote services. Typically usage is to obtain an <code>IRemoteServices</code> object and then call <code>getRemoteUIServices()</code>.
+
 
+
; <code>public IRemoteUIServices getRemoteUIServices(IRemoteServices services)</code> : Retrieve the remote UI services associated with the service provider.
+
  
 
=== IRemoteServices ===
 
=== IRemoteServices ===
  
The <code>IRemoteServices</code> interface is the main entry point into the remote functionality. From here it is possible to gain access to three types of remote services: connection, file, and process. Connection services are for managing connections to the remote system. File services are for copying and manipulating files remotely. Process services are for launching processes on the remote system.
+
The <code>IRemoteServices</code> interface is the main entry point into the remote functionality. From here it is possible to gain access to the connection manager, and to obtain information about the service capabilities.
  
 
; <code>public IRemoteConnectionManager getConnectionManager()</code> : Get the connection manager for the remote service provider.
 
; <code>public IRemoteConnectionManager getConnectionManager()</code> : Get the connection manager for the remote service provider.
 
 
; <code>public IRemoteFileManager getFileManager(IRemoteConnection conn)</code>  : Get the file manager for the remote service provider.
+
; <code>public int getCapabilities()</code>  : Get the capabilities of the remote service provider. This includes information about whether it is possible to create new connections, and what types of functionality the remote services provides. See the <code>IRemoteServices</code> class for a list of the capabilities.
 
 
; <code>public IRemoteProcessBuilder getProcessBuilder(IRemoteConnection conn, List<String>command)</code>  : Get the process builder for the remote service provider. The process builder can be used to invoke the command specified by the argument list.
 
 
; <code>public IRemoteProcessBuilder getProcessBuilder(IRemoteConnection conn, String... command)</code>  : Get the process builder for the remote service provider. The process builder can be used to invoke the command specified by the argument strings.
 
 
 
=== IRemoteConnectionManager ===
 
=== IRemoteConnectionManager ===
  
The <code>IRemoteConnectionManager</code> interface is for managing connections to remote systems. This is a container for the remote connection that is actually managed by the remote service provider, so the name of the connection is only meaningful in the context of the remote provider. Both currently supported remote providers use names to identify connections, and this name is the same one that can be used to look up the connection. Since creating a new connection typically requires interaction with the user, this facility is provided in the remote UI services API.
+
The <code>IRemoteConnectionManager</code> interface is for managing connections to remote systems. Since creating a new connection can require user interaction, there is also functionality in the UI services to help with this.
  
 
; <code>public IRemoteConnection getConnection(String name)</code> : Retrieve a connection using the connection name. A connection name is a string that identifies the connection for the remote service provider.
 
; <code>public IRemoteConnection getConnection(String name)</code> : Retrieve a connection using the connection name. A connection name is a string that identifies the connection for the remote service provider.
  
; <code>public IRemoteConnection[] getConnections()</code> : Retrieve all the connections that are known by the remote service provider.
+
; <code>public List<IRemoteConnection> getConnections()</code> : Retrieve all the connections that are known by the remote service provider.
 
 
 +
; <code>public IRemoteConnectionWorkingCopy newConnection(String name)</code> : Create a new connection with name 'name'.
 +
 
; <code>public void removeConnection(IRemoteConnection connection)</code> : Remove the remote connection.
 
; <code>public void removeConnection(IRemoteConnection connection)</code> : Remove the remote connection.
  
 
=== IRemoteConnection ===
 
=== IRemoteConnection ===
  
The <code>IRemoteConnection</code> interface is for managing a connection to a single remote host. A connection must be established (open) before any other operations are permitted. Connections are passed to other services in order to carry out operations on the remote host.
+
The <code>IRemoteConnection</code> interface is for managing a connection to a single remote host. A connection must be established (open) before any other operations are permitted. Connections are passed to other services in order to carry out operations on the remote host. Connections are read-only objects. In order to change the attributes of a connection, a working copy must be created (see <code>IRemoteConnectionWorkingCopy</code> below).
  
 
; <code>public void close()</code> : Close the remote connection
 
; <code>public void close()</code> : Close the remote connection
Line 79: Line 72:
 
 
 
; <code>public String getName()</code> : Get a unique name for this connection.
 
; <code>public String getName()</code> : Get a unique name for this connection.
 +
 +
; <code>public IRemoteFileManager getFileManager()</code>  : Get the file manager for the remote connection. The file manager can be used to manipulate files on the remote system.
 
 
 +
; <code>public IRemoteProcessBuilder getProcessBuilder(List<String>command)</code>  : Get the process builder for the remote connection. The process builder can be used to invoke the command specified by the argument list.
 +
 +
; <code>public IRemoteProcessBuilder getProcessBuilder(String... command)</code>  : Get the process builder for the remote connection. The process builder can be used to invoke the command specified by the argument strings.
 +
 
; <code>public String getUsername()</code> : Get the username for this connection.
 
; <code>public String getUsername()</code> : Get the username for this connection.
 
 
 +
; <code>public IRemoteConnectionWorkingCopy getWorkingCopy() </code> :  Get a working copy of the connection. Must be used to modify any connection attributes.
 +
 
; <code>public boolean isOpen()</code> : Test if the connection is open. A connection must be open before any operations can be performed.
 
; <code>public boolean isOpen()</code> : Test if the connection is open. A connection must be open before any operations can be performed.
  
 
; <code>public void open(IProgressMonitor monitor) </code> :  Open the connection. Must be called before the connection can be used.
 
; <code>public void open(IProgressMonitor monitor) </code> :  Open the connection. Must be called before the connection can be used.
 +
 +
; <code>public boolean supportsTCPPortForwarding()</code> : Test if this connection supports forwarding of TCP connections.
 +
 +
=== IRemoteConnectionWorkingCopy ===
 +
 +
An <code>IRemoteConnectionWorkingCopy</code> is a writeable copy of the connection. It provides additional methods for modifying the connection attributes. The <code>save()</code> method must be called to save the changes to the original connection.
 
 
 
; <code>public void setAddress(String address)</code> : Set the implementation dependent address for this connection.
 
; <code>public void setAddress(String address)</code> : Set the implementation dependent address for this connection.
 
 
 
; <code>public void setUsername(String username)</code> : Set the username for this connection.
 
; <code>public void setUsername(String username)</code> : Set the username for this connection.
 
; <code>public boolean supportsTCPPortForwarding()</code> : Test if this connection supports forwarding of TCP connections.
 
  
 
=== IRemoteFileManager ===
 
=== IRemoteFileManager ===
Line 107: Line 112:
  
 
The <code>IRemoteProcessBuilder</code> provides remote process operations on a given connection. This interface is intended to be a drop-in replacement for the <code>ProcessBuilder</code> class. See the [http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html <code>java.lang.ProcessBuilder</code>] documentation for a description of the methods.
 
The <code>IRemoteProcessBuilder</code> provides remote process operations on a given connection. This interface is intended to be a drop-in replacement for the <code>ProcessBuilder</code> class. See the [http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html <code>java.lang.ProcessBuilder</code>] documentation for a description of the methods.
 +
 +
== UI Services ==
 +
 +
The remote services package also provides utilities to help manipulate remote resources via the UI. In particular, it provides a main preference page (under "Remote Development > Connections") which allow connections to be created, edited, removed, opened, and closed. In addition to this preference page, a number of other utilities provided, and these are discussed in more detail below.
 +
 +
=== RemoteConnectionWidget ===
 +
 +
This UI widget can be used anywhere the user needs to select or create a connection in the UI. It extends an SWT Composite, so can be used anywhere an ordinary Composite is used.
 +
 +
=== RemoteDirectoryWidget ===
 +
 +
This UI widget provides a directory browser to allow selection of a directory on the remote system.
 +
 +
=== RemoteFileWidget ===
 +
 +
This UI widget provides a file browser to allow selection of one (or more) files on the remote system.
 +
 +
=== RemoteResourceBrowser ===
 +
 +
A dialog that provides a generic method for browsing for files or directories on the target system.
 +
 +
=== RemoteUIServices class ===
 +
 +
If other UI services are required, the <code>RemoteUIServices</code> class provides the main entry point for accessing these. Typically usage is to obtain an <code>IRemoteServices</code> object and then call <code>getRemoteUIServices()</code>. There are also a number of widgets and dialogs that can be used to access remote services.
 +
 +
; <code>public IRemoteUIServices getRemoteUIServices(IRemoteServices services)</code> : Retrieve the remote UI services associated with the service provider.
  
 
=== IRemoteUIServices ===
 
=== IRemoteUIServices ===
  
The <code> IRemoteUIServices</code> interface provides two methods for accessing UI operations. This include methods for manipulating connections (creating, editing, etc.) and for manipulating remote files.
+
The <code>IRemoteUIServices</code> interface provides two methods for accessing UI operations. This include methods for manipulating connections (creating, etc.) and for manipulating remote files.
  
 
; <code>public IRemoteUIConnectionManager getUIConnectionManager()</code> : Get a UI connection manager for managing connections.
 
; <code>public IRemoteUIConnectionManager getUIConnectionManager()</code> : Get a UI connection manager for managing connections.
 
 
 
; <code>public IRemoteUIFileManager getUIFileManager()</code> : Get a UI file manager for managing remote files.
 
; <code>public IRemoteUIFileManager getUIFileManager()</code> : Get a UI file manager for managing remote files.
 +
 +
=== IRemoteUIConnectionManager ===
 +
 +
The <code>IRemoteUIConnectionManager</code> interface is used for manipulating connections in the UI, such as adding, editing, and opening connections.
 +
 +
; <code>public IRemoteUIConnectionWizard getConnectionWizard(Shell shell)</code> : Obtain a wizard for managing connections.
 +
 +
; <code>public void openConnectionWithProgress(Shell shell, IRunnableContext context, IRemoteConnection connection)</code> : Open a connection using a runnable context or progress monitor. Should be used anywhere a connection is opened in the UI.
 +
 +
=== IRemoteUIFileManager ===
 +
 +
The <code>IRemoteUIFileManager</code> interface provides methods for manipulating files or directories on the remote host.
 +
 +
; <code>public IPath browseDirectory(Shell shell, String message, String initialPath)</code> : Browse for a remote directory. The return value is the path of the directory <i>on the remote system</i>.
 +
 +
; <code>public IPath browseFile(Shell shell, String message, String initialPath)</code> : Browse for a remote file. The return value is the path of the file <i>on the remote system</i>.
 +
 +
; <code>public IRemoteConnection getConnection()</code> : Get the last connection that was selected in the browser.
 +
 +
; <code>public void setConnection(IRemoteConnection connection)</code> : Set the connection to use for browsing.
 +
 +
; <code>public void showConnections(boolean enable)</code> : Show a list of available connections in the browser if possible.
 +
 +
== Usage Examples ==
 +
 +
A remote services object can be obtained directly if the ID is known:
 +
 +
<pre>
 +
IRemoteServices services = RemoteServices.getRemoteServices("org.eclipse.remote.JSch");
 +
</pre>
 +
 +
It can also be obtained via a URI:
 +
 +
<pre>
 +
IRemoteServices services = RemoteServices.getRemoteServices(new URI("ssh://user@host/path/to/resource"));
 +
</pre>
 +
 +
Once a services object has been obtained, connections can be manipulated programmatically:
 +
 +
<pre>
 +
IRemoteConnectionManager connMgr = services.getConnectionManager(); // Get the connection manager
 +
IRemoteConnectionWorkingCopy wc = connMgr.newConnection("my connection"); // Create a new connection
 +
wc.setAddress("remote.host.com"); // Set the address (host name)
 +
wc.setUsername("my_username"); // Set the username
 +
wc.setPassword("secret_password"); // Set the password
 +
IRemoteConnection connection = wc.save(); // Save the attributes
 +
</pre>
 +
 +
Connections can be opened or closed programmatically:
 +
 +
<pre>
 +
connection.open(monitor); // Open the connection but allow the user to cancel the progress monitor
 +
connection.close(); // Now close it
 +
</pre>
 +
 +
Open connections can be used to manipulate remote files:
 +
 +
<pre>
 +
IRemoteFileManager fileMgr = connection.getFileManager(); // Get the file manager for the connection
 +
IFileStore file = fileMgr.getResouce("/path/to/resource"); // Get the file store representing the resource
 +
if (file.fetchInfo().exists()) {
 +
    System.out.println("It exists!");
 +
}
 +
</pre>
 +
 +
Remote processes can be run:
 +
 +
<pre>
 +
IRemoteProcessBuilder builder = connection.getProcessBuilder("/bin/ls", "-l"); // Create an 'ls -l' command
 +
IRemoteProcess process = builder.start();
 +
while (!process.isCompleted()) {
 +
    process.waitFor();
 +
}
 +
</pre>

Latest revision as of 08:34, 28 October 2014

This page provides a brief overview of the remote services API. The purpose of this API is to provide a programming interface to remote services that is agnostic to the actual remote services implementation. Currently the only implementation supported is JSch, but support for RSE and Remote Tools (light-weight ssh layer that is part of PTP) are available in PTP. An implementation for the local system (where Eclipse is run) is also provided.

The API is generic enough so that it is possible to use it for all remote *or* local operations. This is useful for situations where both a remote and local mode should be provided, but the programmer wants to avoid two separate code paths.

Types of Services

The API is divided into two types of remote services: UI and non-UI. UI services are for activities such as file browsing that require use of the UI. Non-UI services are purely programmatic. The non-UI services can be used independently of the UI services.

Remote Services Plugins

The remote services are divided into two plugins. These plugins should have no dependencies other than the platform.

  • org.eclipse.remote.core
  • org.eclipse.remote.ui

Remote service implementations provide the actual remote functionality using a particular remote protocol. These are supplied as a set of adapter plugins. There is currently one implementation using JSch.

  • org.eclipse.remote.jsch.core
  • org.eclipse.remote.jsch.ui

These plugins are dependent on the remote services implementations, but are optional for the remote services API. The API will automatically detect the installed plugins.

Core Services

The remote services package provides a set of core services for manipulating remote resources. These are described in more detail below.

RemoteServices class

The RemoteServices class provides the main entry point for accessing remote services. Typically usage is to call getRemoteServices() passing either an ID or a URI to retrieve the remote services implementation. The ID can be obtained using the UI services described below. Once an IRemoteServices object has been obtained, it can be used to access all the remaining remote functionality.

public IRemoteServices getRemoteServices(String id) 
Retrieve the remote service provider associated with id.
public IRemoteServices getRemoteServices(URI uri) 
Retrieve the remote service provider associated with a URI.
public IRemoteConnection getLocalServices() 
Retrieve the local services.

IRemoteServices

The IRemoteServices interface is the main entry point into the remote functionality. From here it is possible to gain access to the connection manager, and to obtain information about the service capabilities.

public IRemoteConnectionManager getConnectionManager() 
Get the connection manager for the remote service provider.
public int getCapabilities()  
Get the capabilities of the remote service provider. This includes information about whether it is possible to create new connections, and what types of functionality the remote services provides. See the IRemoteServices class for a list of the capabilities.

IRemoteConnectionManager

The IRemoteConnectionManager interface is for managing connections to remote systems. Since creating a new connection can require user interaction, there is also functionality in the UI services to help with this.

public IRemoteConnection getConnection(String name) 
Retrieve a connection using the connection name. A connection name is a string that identifies the connection for the remote service provider.
public List<IRemoteConnection> getConnections() 
Retrieve all the connections that are known by the remote service provider.
public IRemoteConnectionWorkingCopy newConnection(String name) 
Create a new connection with name 'name'.
public void removeConnection(IRemoteConnection connection) 
Remove the remote connection.

IRemoteConnection

The IRemoteConnection interface is for managing a connection to a single remote host. A connection must be established (open) before any other operations are permitted. Connections are passed to other services in order to carry out operations on the remote host. Connections are read-only objects. In order to change the attributes of a connection, a working copy must be created (see IRemoteConnectionWorkingCopy below).

public void close() 
Close the remote connection
public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort)  
Forward a local port to a remote port on a remote host.
public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) 
Forward a remote port to a port on different host.
public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor)  
Forward a local port to a remote port on remote host.
public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) 
Forward a remote port to a port on a remote host. The remote port is chosen dynamically and returned by the method.
public String getAddress() 
Get the implementation dependent address for this connection (usually the IP address or FQDN).
public String getName() 
Get a unique name for this connection.
public IRemoteFileManager getFileManager()  
Get the file manager for the remote connection. The file manager can be used to manipulate files on the remote system.
public IRemoteProcessBuilder getProcessBuilder(List<String>command)  
Get the process builder for the remote connection. The process builder can be used to invoke the command specified by the argument list.
public IRemoteProcessBuilder getProcessBuilder(String... command)  
Get the process builder for the remote connection. The process builder can be used to invoke the command specified by the argument strings.
public String getUsername() 
Get the username for this connection.
public IRemoteConnectionWorkingCopy getWorkingCopy()  
Get a working copy of the connection. Must be used to modify any connection attributes.
public boolean isOpen() 
Test if the connection is open. A connection must be open before any operations can be performed.
public void open(IProgressMonitor monitor)  
Open the connection. Must be called before the connection can be used.
public boolean supportsTCPPortForwarding() 
Test if this connection supports forwarding of TCP connections.

IRemoteConnectionWorkingCopy

An IRemoteConnectionWorkingCopy is a writeable copy of the connection. It provides additional methods for modifying the connection attributes. The save() method must be called to save the changes to the original connection.

public void setAddress(String address) 
Set the implementation dependent address for this connection.
public void setUsername(String username) 
Set the username for this connection.

IRemoteFileManager

The IRemoteFileManager interface provides remote file manipulation operations on a given connection. Using this interface, a path can be translated into an IFileStore object, and then manipulated using any of the normal EFS operations (See the EFS documentation in the Platform Plug-in Developer Guide > Programmer's Guide > Advanced resource concepts > Alternate file systems).

public IFileStore getResource(IPath path, IProgressMonitor monitor) 
Get the resource associated with a path. The platform EFS interfaces can then be used to perform operations on the file.
public IPath getWorkingDirectory() 
Get the working directory. Relative paths will be resolved using this path.
public IPath toPath(URI uri) 
Convert URI to a remote path. This path is suitable for direct file operations on the remote system.
public URI toURI(IPath path) 
Convert remote path to equivalent URI. This URI is suitable for EFS operations on the local system.

IRemoteProcessBuilder

The IRemoteProcessBuilder provides remote process operations on a given connection. This interface is intended to be a drop-in replacement for the ProcessBuilder class. See the java.lang.ProcessBuilder documentation for a description of the methods.

UI Services

The remote services package also provides utilities to help manipulate remote resources via the UI. In particular, it provides a main preference page (under "Remote Development > Connections") which allow connections to be created, edited, removed, opened, and closed. In addition to this preference page, a number of other utilities provided, and these are discussed in more detail below.

RemoteConnectionWidget

This UI widget can be used anywhere the user needs to select or create a connection in the UI. It extends an SWT Composite, so can be used anywhere an ordinary Composite is used.

RemoteDirectoryWidget

This UI widget provides a directory browser to allow selection of a directory on the remote system.

RemoteFileWidget

This UI widget provides a file browser to allow selection of one (or more) files on the remote system.

RemoteResourceBrowser

A dialog that provides a generic method for browsing for files or directories on the target system.

RemoteUIServices class

If other UI services are required, the RemoteUIServices class provides the main entry point for accessing these. Typically usage is to obtain an IRemoteServices object and then call getRemoteUIServices(). There are also a number of widgets and dialogs that can be used to access remote services.

public IRemoteUIServices getRemoteUIServices(IRemoteServices services) 
Retrieve the remote UI services associated with the service provider.

IRemoteUIServices

The IRemoteUIServices interface provides two methods for accessing UI operations. This include methods for manipulating connections (creating, etc.) and for manipulating remote files.

public IRemoteUIConnectionManager getUIConnectionManager() 
Get a UI connection manager for managing connections.
public IRemoteUIFileManager getUIFileManager() 
Get a UI file manager for managing remote files.

IRemoteUIConnectionManager

The IRemoteUIConnectionManager interface is used for manipulating connections in the UI, such as adding, editing, and opening connections.

public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) 
Obtain a wizard for managing connections.
public void openConnectionWithProgress(Shell shell, IRunnableContext context, IRemoteConnection connection) 
Open a connection using a runnable context or progress monitor. Should be used anywhere a connection is opened in the UI.

IRemoteUIFileManager

The IRemoteUIFileManager interface provides methods for manipulating files or directories on the remote host.

public IPath browseDirectory(Shell shell, String message, String initialPath) 
Browse for a remote directory. The return value is the path of the directory on the remote system.
public IPath browseFile(Shell shell, String message, String initialPath) 
Browse for a remote file. The return value is the path of the file on the remote system.
public IRemoteConnection getConnection() 
Get the last connection that was selected in the browser.
public void setConnection(IRemoteConnection connection) 
Set the connection to use for browsing.
public void showConnections(boolean enable) 
Show a list of available connections in the browser if possible.

Usage Examples

A remote services object can be obtained directly if the ID is known:

IRemoteServices services = RemoteServices.getRemoteServices("org.eclipse.remote.JSch");

It can also be obtained via a URI:

IRemoteServices services = RemoteServices.getRemoteServices(new URI("ssh://user@host/path/to/resource"));

Once a services object has been obtained, connections can be manipulated programmatically:

IRemoteConnectionManager connMgr = services.getConnectionManager(); // Get the connection manager
IRemoteConnectionWorkingCopy wc = connMgr.newConnection("my connection"); // Create a new connection
wc.setAddress("remote.host.com"); // Set the address (host name)
wc.setUsername("my_username"); // Set the username
wc.setPassword("secret_password"); // Set the password
IRemoteConnection connection = wc.save(); // Save the attributes

Connections can be opened or closed programmatically:

connection.open(monitor); // Open the connection but allow the user to cancel the progress monitor
connection.close(); // Now close it

Open connections can be used to manipulate remote files:

IRemoteFileManager fileMgr = connection.getFileManager(); // Get the file manager for the connection
IFileStore file = fileMgr.getResouce("/path/to/resource"); // Get the file store representing the resource
if (file.fetchInfo().exists()) {
    System.out.println("It exists!");
}

Remote processes can be run:

IRemoteProcessBuilder builder = connection.getProcessBuilder("/bin/ls", "-l"); // Create an 'ls -l' command
IRemoteProcess process = builder.start();
while (!process.isCompleted()) {
    process.waitFor();
}

Back to the top