Class SshRunner

java.lang.Object
nl.knaw.dans.layerstore.SshRunner

public class SshRunner extends Object
A runner for the ssh command line tool, which executes commands on a remote host via SSH.
  • Constructor Details

    • SshRunner

      public SshRunner(Path sshExecutable, String user, String host, Path remoteBaseDir)
      Creates a new SshRunner.
      Parameters:
      sshExecutable - path to the ssh executable
      user - username for the remote host
      host - host name or IP address of the remote host
      remoteBaseDir - base directory on the remote host where archives are stored
    • SshRunner

      public SshRunner(Path sshExecutable, String user, String host, Path remoteBaseDir, int connectionTimeout)
      Creates a new SshRunner.
      Parameters:
      sshExecutable - path to the ssh executable
      user - username for the remote host
      host - host name or IP address of the remote host
      remoteBaseDir - base directory on the remote host where archives are stored
      connectionTimeout - connection timeout in seconds
  • Method Details

    • fileExists

      public boolean fileExists(String archiveName)
      Checks if the given archive name exists on the remote host.
      Parameters:
      archiveName - the name of the archive to check
      Returns:
      true if the archive exists, false otherwise
    • listFiles

      public List<String> listFiles()
      Lists the files in the remote base directory.
      Returns:
      a list of file names in the remote base directory
    • listFiles

      public List<String> listFiles(String flags)
      Lists the files in the remote base directory with the given flags.
      Parameters:
      flags - flags for the ls command
      Returns:
      a list of lines from the ls command
    • runCommand

      public void runCommand(String command)
    • getHost

      public String getHost()
    • getRemoteBaseDir

      public Path getRemoteBaseDir()
    • checkExecutableForSecurity

      protected static String checkExecutableForSecurity(Path path)
    • checkUserOrHostNameForSecurity

      protected static String checkUserOrHostNameForSecurity(String param)
    • checkRemoteBaseDirForSecurity

      protected static String checkRemoteBaseDirForSecurity(String param)