public class SshExec extends RemoteExec
Modifier and Type | Field and Description |
---|---|
protected com.jcraft.jsch.Session |
jschSession |
protected org.kepler.ssh.SshSession |
session |
Constructor and Description |
---|
SshExec(java.lang.String target)
Create and SshExec object from a combined target string.
|
SshExec(java.lang.String user,
java.lang.String host) |
SshExec(java.lang.String user,
java.lang.String host,
int port) |
Modifier and Type | Method and Description |
---|---|
protected int |
_copyTo(java.io.File lfile,
java.lang.String targetPath,
boolean recursive)
Copy _one_ local file to a remote directory Input: file of type File
(which can be a directory) Input must not have wildcards. targetPath is
either a directory or filename
|
void |
addIdentity(java.io.File identity) |
void |
addIdentity(java.lang.String identity)
Add identity file Public-key authentication can be used if you add
identity files
|
void |
addPortForwardL(java.lang.String spec)
Add a local port forwarding to an open connection.
|
void |
addPortForwardR(java.lang.String spec)
Add a remote port forwarding to an open connection.
|
protected static int |
checkAck(java.io.InputStream in) |
void |
closeConnection()
Close the connection This should be called only when there is no more use
of the connection to this user@host Important: the ssh session remains
opened as long as this method is not called, therefore, the the whole
java application will hang at the end until this method is called.
|
int |
copyFrom(java.lang.String rfile,
java.io.File localPath,
boolean recursive)
Copy a remote file into a local file Input: 'rfile' of type String (can
be a directory or filename) 'localPath' is either a directory or filename
Only if 'recursive' is set, will directories copied recursively.
|
int |
executeCmd(java.lang.String command,
java.io.OutputStream streamOut,
java.io.OutputStream streamErr)
Execute a command on the remote machine.
|
int |
executeCmd(java.lang.String command,
java.io.OutputStream streamOut,
java.io.OutputStream streamErr,
java.lang.String thirdPartyTarget)
Execute a command on the remote machine and expect a password/passphrase
question from the command.
|
boolean |
getForcedCleanUp() |
int |
getTimeout() |
java.lang.String |
getwildcardFileListingBBCP(java.lang.String srcConn,
java.lang.String wildcardPattern) |
boolean |
isRemoteFileDirectory(java.lang.String fileName)
Anand: New method added to check if remote file is a directory
Run "cd" command on given file.
|
boolean |
openConnection()
Open the connection to the remote machine now.
|
void |
removePortForwardL(int port,
boolean closeIfLast)
Remove a local port forwarding.
|
void |
removePortForwardR(int port,
boolean closeIfLast)
Remove a remote port forwarding.
|
void |
setcmdLineOptions(java.lang.String cmdLineOptions) |
void |
setForcedCleanUp(boolean foo)
Specify if killing of remote processes (i.e. clean-up) after error or
timeout is required.
|
void |
setPortForwardingL(java.lang.String spec)
Set a local port forwarding before the connection is made.
|
void |
setPortForwardingR(java.lang.String spec)
Set a remote port forwarding before the connection is made.
|
void |
setProtocolPath(java.lang.String protocolPath) |
void |
setPseudoTerminal(boolean pseudoTerminal) |
void |
setTimeout(int seconds)
Set timeout for the operations.
|
void |
setTimeout(int seconds,
boolean stdout,
boolean stderr)
Set timeout for the operations.
|
copyFrom, copyTo, copyTo, createDir, deleteFile, kill
protected org.kepler.ssh.SshSession session
protected com.jcraft.jsch.Session jschSession
public SshExec(java.lang.String user, java.lang.String host)
public SshExec(java.lang.String user, java.lang.String host, int port)
public SshExec(java.lang.String target)
public boolean openConnection() throws SshException
openConnection
in interface ExecInterface
openConnection
in class RemoteExec
SshException
public void closeConnection()
closeConnection
in interface ExecInterface
closeConnection
in class RemoteExec
public void addIdentity(java.lang.String identity)
public void addIdentity(java.io.File identity)
public void setPortForwardingL(java.lang.String spec) throws SshException
SshException
public void addPortForwardL(java.lang.String spec)
public void setPortForwardingR(java.lang.String spec) throws SshException
SshException
public void addPortForwardR(java.lang.String spec)
public void removePortForwardL(int port, boolean closeIfLast) throws SshException
port
- the local port that is forwarded.closeIfLast
- If true, and there are no additional local ports
forwarded, close the connection.SshException
public void removePortForwardR(int port, boolean closeIfLast) throws SshException
port
- the remote port that is forwarded.closeIfLast
- If true, and there are no additional remote ports
forwarded, close the connection.SshException
public void setTimeout(int seconds, boolean stdout, boolean stderr)
public void setForcedCleanUp(boolean foo)
public int executeCmd(java.lang.String command, java.io.OutputStream streamOut, java.io.OutputStream streamErr) throws ExecException
ExecTimeoutException
- if the command failed because of timeoutSshException
- if an error occurs for the ssh connection during the command
executionExecException
public int executeCmd(java.lang.String command, java.io.OutputStream streamOut, java.io.OutputStream streamErr, java.lang.String thirdPartyTarget) throws ExecException
ExecTimeoutException
- if the command failed because of timeoutSshException
- if an error occurs for the ssh connection during the command
execution Note: in this method, the SSH Channel is forcing a
pseudo-terminal allocation {see setPty(true)} to allow remote
commands to read something from their stdin (i.e. from us
here), thus, (1) remote environment is not set from
.bashrc/.cshrc and (2) stdout and stderr come back merged in
one stream.ExecException
protected int _copyTo(java.io.File lfile, java.lang.String targetPath, boolean recursive) throws SshException
_copyTo
in class RemoteExec
SshException
protected static int checkAck(java.io.InputStream in) throws java.io.IOException, SshException
java.io.IOException
SshException
public boolean isRemoteFileDirectory(java.lang.String fileName) throws java.lang.Exception
fileName
- : file which is to be checked to see if it is a directoryjava.lang.Exception
public int copyFrom(java.lang.String rfile, java.io.File localPath, boolean recursive) throws SshException
copyFrom
in interface ExecInterface
copyFrom
in class RemoteExec
SshException
public void setPseudoTerminal(boolean pseudoTerminal)
public void setProtocolPath(java.lang.String protocolPath)
public void setcmdLineOptions(java.lang.String cmdLineOptions)
public boolean getForcedCleanUp()
getForcedCleanUp
in class RemoteExec
public int getTimeout()
getTimeout
in class RemoteExec
public void setTimeout(int seconds)
ExecInterface
public java.lang.String getwildcardFileListingBBCP(java.lang.String srcConn, java.lang.String wildcardPattern) throws ExecException
ExecException