FileDocCategorySizeDatePackage
SSHBase.javaAPI DocApache Ant 1.705788Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.ssh

SSHBase

public abstract class SSHBase extends org.apache.tools.ant.Task implements LogListener
Base class for Ant tasks using jsch.
since
Ant 1.6

Fields Summary
private static final int
SSH_PORT
Default listen port for SSH daemon
private String
host
private String
knownHosts
private int
port
private boolean
failOnError
private boolean
verbose
private SSHUserInfo
userInfo
Constructors Summary
public SSHBase()
Constructor for SSHBase.


            
      
        super();
        userInfo = new SSHUserInfo();
    
Methods Summary
public booleangetFailonerror()
Get the failonerror flag.

return
the failonerror flag

        return failOnError;
    
public java.lang.StringgetHost()
Get the host.

return
the host

        return host;
    
public intgetPort()
Get the port attribute.

return
the port

        return port;
    
protected SSHUserInfogetUserInfo()
Get the user information.

return
the user information

        return userInfo;
    
public booleangetVerbose()
Get the verbose flag.

return
the verbose flag
since
Ant 1.6.2

        return verbose;
    
public voidinit()
Initialize the task. This initializizs the known hosts and sets the default port.

throws
BuildException on error

        super.init();
        this.knownHosts = System.getProperty("user.home") + "/.ssh/known_hosts";
        this.port = SSH_PORT;
    
protected com.jcraft.jsch.SessionopenSession()
Open an ssh seession.

return
the opened session
throws
JSchException on error

        JSch jsch = new JSch();
        if (null != userInfo.getKeyfile()) {
            jsch.addIdentity(userInfo.getKeyfile());
        }

        if (!userInfo.getTrust() && knownHosts != null) {
            log("Using known hosts: " + knownHosts, Project.MSG_DEBUG);
            jsch.setKnownHosts(knownHosts);
        }

        Session session = jsch.getSession(userInfo.getName(), host, port);
        session.setUserInfo(userInfo);
        log("Connecting to " + host + ":" + port);
        session.connect();
        return session;
    
public voidsetFailonerror(boolean failure)
Set the failonerror flag. Default is true

param
failure if true throw a build exception when a failure occuries, otherwise just log the failure and continue

        failOnError = failure;
    
public voidsetHost(java.lang.String host)
Remote host, either DNS name or IP.

param
host The new host value

        this.host = host;
    
public voidsetKeyfile(java.lang.String keyfile)
Sets the keyfile for the user.

param
keyfile The new keyfile value

        userInfo.setKeyfile(keyfile);
    
public voidsetKnownhosts(java.lang.String knownHosts)
Sets the path to the file that has the identities of all known hosts. This is used by SSH protocol to validate the identity of the host. The default is ${user.home}/.ssh/known_hosts.

param
knownHosts a path to the known hosts file.

        this.knownHosts = knownHosts;
    
public voidsetPassphrase(java.lang.String passphrase)
Sets the passphrase for the users key.

param
passphrase The new passphrase value

        userInfo.setPassphrase(passphrase);
    
public voidsetPassword(java.lang.String password)
Sets the password for the user.

param
password The new password value

        userInfo.setPassword(password);
    
public voidsetPort(int port)
Changes the port used to connect to the remote host.

param
port port number of remote host.

        this.port = port;
    
public voidsetTrust(boolean yesOrNo)
Setting this to true trusts hosts whose identity is unknown.

param
yesOrNo if true trust the identity of unknown hosts.

        userInfo.setTrust(yesOrNo);
    
public voidsetUsername(java.lang.String username)
Username known to remote host.

param
username The new username value

        userInfo.setName(username);
    
public voidsetVerbose(boolean verbose)
Set the verbose flag.

param
verbose if true output more verbose logging
since
Ant 1.6.2

        this.verbose = verbose;