public boolean executeRemoteCommand(IProgressMonitor monitor, String command, String[] args) throws CoreException { if (remoteConnection == null) { throw new CoreException( new Status( IStatus.ERROR, EnvironmentPlugin.getUniqueIdentifier(), Messages.SSHTargetControl_5, null)); } for (int i = 0; i < args.length; i++) { command += (" " + args[i]); // $NON-NLS-1$ } try { IRemoteExecutionManager executionManager = remoteConnection.createRemoteExecutionManager(); executionManager.getExecutionTools().executeWithExitValue(command); executionManager.close(); return true; } catch (RemoteConnectionException e) { throw new CoreException( new Status( IStatus.ERROR, EnvironmentPlugin.getUniqueIdentifier(), 0, Messages.SSHTargetControl_2, e)); } catch (CancelException e) { throw new CoreException( new Status( IStatus.ERROR, EnvironmentPlugin.getUniqueIdentifier(), 0, Messages.SSHTargetControl_3, e)); } catch (RemoteExecutionException e) { throw new CoreException( new Status( IStatus.ERROR, EnvironmentPlugin.getUniqueIdentifier(), 0, Messages.SSHTargetControl_4, e)); } }
/** * Create the SSH connection to the remote target environment. First, {@link * #setConnectionParameters(org.eclipse.ptp.remotetools.environment.control.SSHTargetControl.SSHParameters)} * must be called. * * @param monitor progress monitor * @throws RemoteConnectionException */ protected synchronized void connect(IProgressMonitor monitor) throws RemoteConnectionException { Assert.isNotNull(fAuthInfo, "missing ssh parameters"); // $NON-NLS-1$ /* * Try to connect, else undo the connection. */ if (remoteConnection == null) { remoteConnection = RemotetoolsPlugin.createSSHConnection(); } try { remoteConnection.connect( fAuthInfo, fConfig.getConnectionAddress(), fConfig.getConnectionPort(), fConfig.getCipherType(), fConfig.getConnectionTimeout() * 1000, monitor); } catch (RemoteConnectionException e) { disconnect(); throw e; } }
/** * Checks if the connection to the remote target environment is alive. * * @return */ protected boolean isConnected() { return (remoteConnection != null) && (remoteConnection.isConnected()); }
/** * Guarantees that the connection to the remote host is closed and releases ressources allocated * to the connection. */ protected synchronized void disconnect() { if (remoteConnection != null) { remoteConnection.disconnect(); } }
/** * Create a remote execution manager that may be used to do operations on the remote target * environment. * * @return * @throws RemoteConnectionException */ protected IRemoteExecutionManager createRemoteExecutionManager() throws RemoteConnectionException { return remoteConnection.createRemoteExecutionManager(); }