Class SSHSession


  • public class SSHSession
    extends Object
    Author:
    Nick Collier
    • Constructor Detail

      • SSHSession

        public SSHSession​(com.jcraft.jsch.Session session)
    • Method Detail

      • executeBackgroundCommand

        public void executeBackgroundCommand​(String cmd)
                                      throws com.jcraft.jsch.JSchException
        Executes teh specified command in the background.
        Parameters:
        cmd -
        Throws:
        com.jcraft.jsch.JSchException
      • listRemoteDirectory

        public List<String> listRemoteDirectory​(String remoteDir)
                                         throws com.jcraft.jsch.JSchException,
                                                com.jcraft.jsch.SftpException
        Returns the listing of the specified remote directory as a list of Strings.
        Parameters:
        remoteDir -
        Returns:
        Throws:
        com.jcraft.jsch.JSchException
        com.jcraft.jsch.SftpException
      • listRemoteDirectory

        public List<String> listRemoteDirectory​(String remoteDir,
                                                boolean recurse)
                                         throws com.jcraft.jsch.JSchException,
                                                com.jcraft.jsch.SftpException
        Returns the file listing of the specified remote directory as a list of Strings with an option to recurse into any directories that are found. If recurse is true then the files in the subdirectories will be returned with that subdirectory prefixed to the file name (e.g. output/file1).
        Parameters:
        remoteDir -
        Returns:
        Throws:
        com.jcraft.jsch.JSchException
        com.jcraft.jsch.SftpException
      • executeCmd

        public int executeCmd​(String cmd,
                              org.apache.log4j.Level level)
                       throws com.jcraft.jsch.JSchException
        Execute the specifed command on the remote machine and wait for the resutl.
        Parameters:
        cmd -
        level -
        Returns:
        Throws:
        com.jcraft.jsch.JSchException
      • executeCmd

        public int executeCmd​(String cmd,
                              StringBuilder builder,
                              boolean setErrStream)
                       throws com.jcraft.jsch.JSchException,
                              IOException
        Execute the specified command on the remote machine and append any output to the StringBuilder. If setErrStream is true then errors will be directory to a LoggingOutputStream.
        Parameters:
        cmd -
        builder -
        setErrStream -
        Returns:
        Throws:
        com.jcraft.jsch.JSchException
        IOException
      • copyFileToRemote

        public void copyFileToRemote​(File localFile)
                              throws com.jcraft.jsch.JSchException,
                                     com.jcraft.jsch.SftpException
        Compies the specified file to the home directory of the user used to log in to the remote.
        Parameters:
        localFile -
        Throws:
        com.jcraft.jsch.JSchException
        com.jcraft.jsch.SftpException
      • copyFileToRemote

        public void copyFileToRemote​(File localFile,
                                     String remoteDirectory)
                              throws com.jcraft.jsch.JSchException,
                                     com.jcraft.jsch.SftpException
        Copies the specified file to the specified remote directory.
        Parameters:
        localFile -
        remoteDirectory -
        Throws:
        com.jcraft.jsch.JSchException
        com.jcraft.jsch.SftpException
      • copyFileFromRemote

        public File copyFileFromRemote​(String localDir,
                                       File remoteFile,
                                       boolean preserveRemotePath)
                                throws com.jcraft.jsch.SftpException,
                                       com.jcraft.jsch.JSchException
        Copies the specified remote file to the specified local directory. If preserveRemotePath is true then path will be preserved when the file is copied. For example, assuming a local directory of "foo", then copying "output/out.txt" will create "foo/output/out.txt".
        Parameters:
        localDir -
        remoteFile -
        preserveRemotePath -
        Returns:
        Throws:
        com.jcraft.jsch.SftpException
        com.jcraft.jsch.JSchException
      • copyFilesFromRemote

        public List<File> copyFilesFromRemote​(String localDir,
                                              List<File> remoteFiles,
                                              boolean preserveRemotePath)
                                       throws com.jcraft.jsch.SftpException,
                                              com.jcraft.jsch.JSchException
        Copies files from the remote to the local directory preserving the directory structure. If preserveRemotePath is true then path will be preserved when the file is copied. For example, assuming a local directory of "foo", then copying "output/out.txt" will create "foo/output/out.txt".
        Parameters:
        localDir -
        remoteFiles -
        Returns:
        Throws:
        com.jcraft.jsch.SftpException
        com.jcraft.jsch.JSchException
      • disconnect

        public void disconnect()