public class JSchConnection extends java.lang.Object implements IRemoteConnectionControlService, IRemoteConnectionPropertyService, IRemotePortForwardingService, IRemoteProcessService, IRemoteConnectionHostService, IRemoteConnectionChangeListener
Modifier and Type | Class and Description |
---|---|
static class |
JSchConnection.Factory |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ADDRESS_ATTR |
static boolean |
DEFAULT_IS_PASSWORD |
static java.lang.String |
DEFAULT_LOGIN_SHELL_COMMAND |
static int |
DEFAULT_PORT |
static int |
DEFAULT_TIMEOUT |
static boolean |
DEFAULT_USE_LOGIN_SHELL |
static java.lang.String |
EMPTY_STRING |
static java.lang.String |
IS_PASSWORD_ATTR |
static java.lang.String |
JSCH_ID |
static java.lang.String |
LOGIN_SHELL_COMMAND_ATTR |
static java.lang.String |
PASSPHRASE_ATTR |
static java.lang.String |
PASSWORD_ATTR |
static java.lang.String |
PORT_ATTR |
static java.lang.String |
PROXYCOMMAND_ATTR |
static java.lang.String |
PROXYCONNECTION_ATTR |
static java.lang.String |
TIMEOUT_ATTR |
static java.lang.String |
USE_LOGIN_SHELL_ATTR |
static java.lang.String |
USERNAME_ATTR |
Constructor and Description |
---|
JSchConnection(IRemoteConnection connection) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the connection.
|
void |
connectionChanged(RemoteConnectionChangeEvent event)
Notifies this listener that the status of a connection has changed.
|
void |
forwardLocalPort(int localPort,
java.lang.String fwdAddress,
int fwdPort)
Forward local port localPort to remote port fwdPort on remote machine fwdAddress.
|
int |
forwardLocalPort(java.lang.String fwdAddress,
int fwdPort,
org.eclipse.core.runtime.IProgressMonitor monitor)
Forward a local port to remote port fwdPort on remote machine fwdAddress.
|
void |
forwardRemotePort(int remotePort,
java.lang.String fwdAddress,
int fwdPort)
Forward remote port remotePort to port fwdPort on machine fwdAddress.
|
int |
forwardRemotePort(java.lang.String fwdAddress,
int fwdPort,
org.eclipse.core.runtime.IProgressMonitor monitor)
Forward a remote port to port fwdPort on remote machine fwdAddress.
|
java.util.Map<java.lang.String,java.lang.String> |
getEnv()
Returns an unmodifiable string map view of the remote environment.
|
java.lang.String |
getEnv(java.lang.String name)
Returns the value of an environment variable.
|
com.jcraft.jsch.ChannelExec |
getExecChannel()
Open an exec channel to the remote host.
|
java.lang.String |
getHostname()
Obtain the hostname associated with this connection.
|
java.lang.String |
getLoginShellCommand()
Get the login shell command if useLoginShell is true
|
java.lang.String |
getPassphrase() |
java.lang.String |
getPassword() |
int |
getPort()
Obtain the port associated with this connection
|
IRemoteProcessBuilder |
getProcessBuilder(java.util.List<java.lang.String> command)
Get a process builder for creating remote processes
|
IRemoteProcessBuilder |
getProcessBuilder(java.lang.String... command)
Get a process builder for creating remote processes
|
java.lang.String |
getProperty(java.lang.String key)
Gets the remote system property indicated by the specified key.
|
java.lang.String |
getProxyCommand()
Gets the proxy command.
|
JSchConnection |
getProxyConnection()
Gets the proxy connection.
|
java.lang.String |
getProxyConnectionName()
Gets the proxy connection name
|
IRemoteConnection |
getRemoteConnection() |
com.jcraft.jsch.ChannelSftp |
getSftpCommandChannel()
Open an sftp command channel to the remote host.
|
com.jcraft.jsch.ChannelShell |
getShellChannel()
Open a shell channel to the remote host.
|
com.jcraft.jsch.Channel |
getStreamForwarder(java.lang.String host,
int port) |
int |
getTimeout()
Obtain the timeout used when establishing the connection.
|
java.lang.String |
getUsername()
Obtain the username associated with this connection.
|
java.lang.String |
getWorkingDirectory()
Get the working directory.
|
boolean |
hasOpenSession()
Test if the connection has a valid open session.
|
boolean |
isOpen()
Test if the connection is open.
|
boolean |
isPasswordAuth() |
com.jcraft.jsch.ChannelSftp |
newSftpChannel()
Open a channel for long running commands.
|
void |
open(org.eclipse.core.runtime.IProgressMonitor monitor)
Open the connection.
|
void |
openMinimal(org.eclipse.core.runtime.IProgressMonitor monitor)
Open ssh connection without full setup (environment, sftp)
|
void |
removeLocalPortForwarding(int port)
Remove the local port forwarding associated with the given port.
|
void |
removeRemotePortForwarding(int port)
Remove the remote port forwarding associated with the given port.
|
void |
setHostname(java.lang.String hostname)
Set the hostname associated with this connection.
|
void |
setPassphrase(java.lang.String passphrase)
Set the pass phrase associated with this connection.
|
void |
setPassword(java.lang.String password)
Set the password associated with this connection.
|
void |
setPort(int port)
Set the port used for the connection.
|
void |
setTimeout(int timeout)
Set the timeout used when establishing the connection.
|
void |
setUseLoginShell(boolean useLogingShell)
Set the flag indicating a login shell should be stated for this connection.
|
void |
setUsePassword(boolean usePassword)
Set the connection to try password authentication first.
|
void |
setUsername(java.lang.String username)
Set the username associated with this connection.
|
void |
setWorkingDirectory(java.lang.String path)
Set the working directory while the connection is open.
|
boolean |
useLoginShell()
Obtain the flag that indicates a login shell should be started once the connection is established
|
public static final java.lang.String JSCH_ID
public static final java.lang.String ADDRESS_ATTR
public static final java.lang.String USERNAME_ATTR
public static final java.lang.String PASSWORD_ATTR
public static final java.lang.String PORT_ATTR
public static final java.lang.String PROXYCONNECTION_ATTR
public static final java.lang.String PROXYCOMMAND_ATTR
public static final java.lang.String IS_PASSWORD_ATTR
public static final java.lang.String PASSPHRASE_ATTR
public static final java.lang.String TIMEOUT_ATTR
public static final java.lang.String USE_LOGIN_SHELL_ATTR
public static final java.lang.String LOGIN_SHELL_COMMAND_ATTR
public static final int DEFAULT_PORT
public static final int DEFAULT_TIMEOUT
public static final boolean DEFAULT_IS_PASSWORD
public static final boolean DEFAULT_USE_LOGIN_SHELL
public static final java.lang.String DEFAULT_LOGIN_SHELL_COMMAND
public static final java.lang.String EMPTY_STRING
public JSchConnection(IRemoteConnection connection)
public void connectionChanged(RemoteConnectionChangeEvent event)
IRemoteConnectionChangeListener
connectionChanged
in interface IRemoteConnectionChangeListener
event
- the connection change eventpublic IRemoteConnection getRemoteConnection()
getRemoteConnection
in interface IRemoteConnection.Service
public void close()
IRemoteConnectionControlService
close
in interface IRemoteConnectionControlService
public void forwardLocalPort(int localPort, java.lang.String fwdAddress, int fwdPort) throws RemoteConnectionException
IRemotePortForwardingService
forwardLocalPort
in interface IRemotePortForwardingService
localPort
- local port to forwardfwdAddress
- address of remote machinefwdPort
- remote port on remote machineRemoteConnectionException
public int forwardLocalPort(java.lang.String fwdAddress, int fwdPort, org.eclipse.core.runtime.IProgressMonitor monitor) throws RemoteConnectionException
IRemotePortForwardingService
forwardLocalPort
in interface IRemotePortForwardingService
RemoteConnectionException
public void forwardRemotePort(int remotePort, java.lang.String fwdAddress, int fwdPort) throws RemoteConnectionException
IRemotePortForwardingService
forwardRemotePort
in interface IRemotePortForwardingService
remotePort
- remote port to forwardfwdAddress
- address of recipient machinefwdPort
- port on recipient machineRemoteConnectionException
public int forwardRemotePort(java.lang.String fwdAddress, int fwdPort, org.eclipse.core.runtime.IProgressMonitor monitor) throws RemoteConnectionException
IRemotePortForwardingService
forwardRemotePort
in interface IRemotePortForwardingService
RemoteConnectionException
public java.lang.String getHostname()
IRemoteConnectionHostService
getHostname
in interface IRemoteConnectionHostService
public java.util.Map<java.lang.String,java.lang.String> getEnv()
IRemoteProcessService
getEnv
in interface IRemoteProcessService
public java.lang.String getEnv(java.lang.String name)
IRemoteProcessService
getEnv
in interface IRemoteProcessService
name
- name of the environment variablepublic com.jcraft.jsch.ChannelExec getExecChannel() throws RemoteConnectionException
RemoteConnectionException
- if a channel could not be openedpublic com.jcraft.jsch.ChannelShell getShellChannel() throws RemoteConnectionException
RemoteConnectionException
- if a channel could not be openedpublic java.lang.String getPassphrase()
public java.lang.String getPassword()
public int getPort()
IRemoteConnectionHostService
getPort
in interface IRemoteConnectionHostService
public IRemoteProcessBuilder getProcessBuilder(java.util.List<java.lang.String> command)
IRemoteProcessService
getProcessBuilder
in interface IRemoteProcessService
public IRemoteProcessBuilder getProcessBuilder(java.lang.String... command)
IRemoteProcessService
getProcessBuilder
in interface IRemoteProcessService
public java.lang.String getProperty(java.lang.String key)
IRemoteConnectionPropertyService
getProperty
in interface IRemoteConnectionPropertyService
key
- the name of the propertypublic java.lang.String getLoginShellCommand()
public java.lang.String getProxyCommand()
public JSchConnection getProxyConnection()
public java.lang.String getProxyConnectionName()
public com.jcraft.jsch.ChannelSftp getSftpCommandChannel() throws RemoteConnectionException
RemoteConnectionException
- if a channel could not be openedpublic com.jcraft.jsch.ChannelSftp newSftpChannel() throws RemoteConnectionException
RemoteConnectionException
- if a channel could not be openedpublic com.jcraft.jsch.Channel getStreamForwarder(java.lang.String host, int port) throws RemoteConnectionException
RemoteConnectionException
public int getTimeout()
IRemoteConnectionHostService
getTimeout
in interface IRemoteConnectionHostService
public java.lang.String getUsername()
IRemoteConnectionHostService
getUsername
in interface IRemoteConnectionHostService
public java.lang.String getWorkingDirectory()
IRemoteProcessService
getWorkingDirectory
in interface IRemoteProcessService
public boolean hasOpenSession()
public boolean isOpen()
IRemoteConnectionControlService
isOpen
in interface IRemoteConnectionControlService
public boolean isPasswordAuth()
public void open(org.eclipse.core.runtime.IProgressMonitor monitor) throws RemoteConnectionException
IRemoteConnectionControlService
open
in interface IRemoteConnectionControlService
monitor
- the progress monitor to use for reporting progress to the user. It is the caller's responsibility to call done()
on the given monitor. Accepts null, indicating that no progress should be reported and that the operation cannot
be cancelled.RemoteConnectionException
public void openMinimal(org.eclipse.core.runtime.IProgressMonitor monitor) throws RemoteConnectionException
monitor
- RemoteConnectionException
org.eclipse.remote.core.IRemoteConnection#open()
public void removeLocalPortForwarding(int port) throws RemoteConnectionException
IRemotePortForwardingService
removeLocalPortForwarding
in interface IRemotePortForwardingService
port
- forwarded portRemoteConnectionException
public void removeRemotePortForwarding(int port) throws RemoteConnectionException
IRemotePortForwardingService
removeRemotePortForwarding
in interface IRemotePortForwardingService
port
- forwarded portRemoteConnectionException
public void setWorkingDirectory(java.lang.String path)
IRemoteProcessService
setWorkingDirectory
in interface IRemoteProcessService
path
- String representing the current working directorypublic boolean useLoginShell()
IRemoteConnectionHostService
useLoginShell
in interface IRemoteConnectionHostService
public void setHostname(java.lang.String hostname)
IRemoteConnectionHostService
setHostname
in interface IRemoteConnectionHostService
hostname
- new hostname for connectionpublic void setPassphrase(java.lang.String passphrase)
IRemoteConnectionHostService
setPassphrase
in interface IRemoteConnectionHostService
public void setPassword(java.lang.String password)
IRemoteConnectionHostService
setPassword
in interface IRemoteConnectionHostService
password
- new password for connectionpublic void setPort(int port)
IRemoteConnectionHostService
setPort
in interface IRemoteConnectionHostService
port
- new port for connectionpublic void setTimeout(int timeout)
IRemoteConnectionHostService
setTimeout
in interface IRemoteConnectionHostService
timeout
- new timeout valuepublic void setUseLoginShell(boolean useLogingShell)
IRemoteConnectionHostService
setUseLoginShell
in interface IRemoteConnectionHostService
useLogingShell
- true to start a login shellpublic void setUsePassword(boolean usePassword)
IRemoteConnectionHostService
setUsePassword
in interface IRemoteConnectionHostService
usePassword
- use password authenticationpublic void setUsername(java.lang.String username)
IRemoteConnectionHostService
setUsername
in interface IRemoteConnectionHostService
username
- new username for connection