org.gridbus.broker.util
Class SSHSession

java.lang.Object
  extended by org.gridbus.broker.util.SSHSession

public class SSHSession
extends java.lang.Object

Author:
Marcos Represents an SSH Session with a remote node.

Constructor Summary
SSHSession()
          The SSHSession is a utility class for managing SSH sessions.
SSHSession(java.lang.String host, java.lang.String user, java.lang.String pass)
          Constructor receives hostname, user and password
 
Method Summary
 void close()
          Closes session
 boolean connect()
          initializes the SSH session
 boolean detectFile(java.lang.String remoteFile)
          Detect file on the remote host by using SFTP
 java.io.InputStream executeAndGetResult(java.lang.String command)
          Execute a command on the remote node
 void executeCmd(java.lang.String command)
          Execute a command on the remote node
 java.lang.String getPassword()
          Returns SSH password
 int getPort()
          Sets SSH port
 java.lang.String getRemoteHost()
          Returns client hostname
 java.lang.String getUsername()
          Returns the processor speed.
static void main(java.lang.String[] args)
           
 com.sshtools.j2ssh.session.SessionChannelClient openChannel(java.lang.String type)
          open a session channel for command execution
 com.sshtools.j2ssh.SftpClient openSftpClient()
          Creates a SftpClient for file transmission
 void P()
           
 boolean scpFrom(java.lang.String remoteFile, java.lang.String localFile)
          Copy a file from remote node using SSH/SCP
 boolean scpFrom(java.lang.String remoteFile, java.lang.String localFile, int tries)
          Copies a file from a remote node by using SCP.
 boolean scpTo(java.io.InputStream stream, long size, java.lang.String localFile, java.lang.String remoteFile)
          Send a file to remote node by SCP
 boolean scpTo(java.lang.String localFile, java.lang.String remoteFile)
          Send a file to remote node by SCP
 void setPassword(java.lang.String pass)
          Sets the password used to establish a ssh session with a Xgrid client.
 void setPort(int port)
          Sets SSH port
 void setRemoteHost(java.lang.String host)
          Sets client hostname
 void setTimeout(int time)
          Sets timeout
 void setUsername(java.lang.String user)
          Sets the username used to establish a ssh session with a Xgrid client.
 boolean sFtpFrom(java.lang.String remoteFile, java.lang.String localFile)
          Copies a file from a remote host by using SFTP.
 boolean sFtpFrom(java.lang.String remoteFile, java.lang.String localFile, int tries)
          Copies a file from a remote host by using SFTP.
 boolean sFtpTo(java.lang.String localFile, java.lang.String remoteFile)
           
 void V()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSHSession

public SSHSession()
The SSHSession is a utility class for managing SSH sessions.


SSHSession

public SSHSession(java.lang.String host,
                  java.lang.String user,
                  java.lang.String pass)
Constructor receives hostname, user and password

Parameters:
host -
user -
pass -
Method Detail

getUsername

public java.lang.String getUsername()
Returns the processor speed.

Returns:
string

setUsername

public void setUsername(java.lang.String user)
Sets the username used to establish a ssh session with a Xgrid client.

Parameters:
user -

setPassword

public void setPassword(java.lang.String pass)
Sets the password used to establish a ssh session with a Xgrid client.

Parameters:
pass -

getPassword

public java.lang.String getPassword()
Returns SSH password

Returns:

setPort

public void setPort(int port)
Sets SSH port

Parameters:
port -

getPort

public int getPort()
Sets SSH port

Returns:

setRemoteHost

public void setRemoteHost(java.lang.String host)
Sets client hostname

Parameters:
host -

getRemoteHost

public java.lang.String getRemoteHost()
Returns client hostname

Returns:

setTimeout

public void setTimeout(int time)
Sets timeout

Parameters:
time -

P

public void P()

V

public void V()

connect

public boolean connect()
initializes the SSH session

Returns:
true if the initialization was successful initialized

openChannel

public com.sshtools.j2ssh.session.SessionChannelClient openChannel(java.lang.String type)
open a session channel for command execution

Parameters:
type -
Returns:
SessionChannelClient

openSftpClient

public com.sshtools.j2ssh.SftpClient openSftpClient()
Creates a SftpClient for file transmission

Returns:
SftpClient

scpTo

public boolean scpTo(java.lang.String localFile,
                     java.lang.String remoteFile)
Send a file to remote node by SCP

Parameters:
remoteFile -
localFile -
Returns:
true if the file was been transmitted

scpTo

public boolean scpTo(java.io.InputStream stream,
                     long size,
                     java.lang.String localFile,
                     java.lang.String remoteFile)
Send a file to remote node by SCP

Parameters:
stream -
size -
localFile -
remoteFile -
Returns:

scpFrom

public boolean scpFrom(java.lang.String remoteFile,
                       java.lang.String localFile,
                       int tries)
Copies a file from a remote node by using SCP. This method tries to check if the file exists. You can specify the number of seconds it will try to check for the remote file on the remote node

Parameters:
remoteFile -
localFile -
tries -
Returns:

scpFrom

public boolean scpFrom(java.lang.String remoteFile,
                       java.lang.String localFile)
Copy a file from remote node using SSH/SCP

Parameters:
localFile -
remoteFile -
Returns:
true if the file was correctly copied back

sFtpTo

public boolean sFtpTo(java.lang.String localFile,
                      java.lang.String remoteFile)
Parameters:
localFile -
remoteFile -
Returns:

sFtpFrom

public boolean sFtpFrom(java.lang.String remoteFile,
                        java.lang.String localFile,
                        int tries)
Copies a file from a remote host by using SFTP.

Parameters:
remoteFile - Remote file name
localFile - Local file name
tries - Number of tries to check if the remote file exist on the remote host. Each second an attempt to check the file on the remote node is done.
Returns:
true if the file was copied.

sFtpFrom

public boolean sFtpFrom(java.lang.String remoteFile,
                        java.lang.String localFile)
Copies a file from a remote host by using SFTP.

Parameters:
remoteFile - Remote file name
localFile - Local file name
Returns:
true if the file was copied.

detectFile

public boolean detectFile(java.lang.String remoteFile)
Detect file on the remote host by using SFTP

Parameters:
remoteFile - Remote file name
Returns:
true if the file exists on the remote node

executeAndGetResult

public java.io.InputStream executeAndGetResult(java.lang.String command)
Execute a command on the remote node

Parameters:
command -
Returns:

executeCmd

public void executeCmd(java.lang.String command)
Execute a command on the remote node

Parameters:
command -

close

public void close()
Closes session


main

public static final void main(java.lang.String[] args)