Class SftpConnector

java.lang.Object
org.kiwiproject.jsch.SftpConnector

public class SftpConnector extends Object
A simple wrapper around a JSch instance that handles connecting and disconnecting using the configuration specified in an SftpConfig.
Implementation Note:
This requires JSch being available at runtime.
  • Constructor Details

    • SftpConnector

      public SftpConnector(SftpConfig config)
      Construct using the given SftpConfig.

      The instance is not connected; call connect() to open a connection.

      Parameters:
      config - the SFTP configuration
    • SftpConnector

      public SftpConnector(com.jcraft.jsch.JSch jsch, SftpConfig config)
      Construct using the given JSch and SftpConfig.

      The instance is not connected; call connect() to open a connection.

      Parameters:
      jsch - the JSch instance to use
      config - the SFTP configuration
  • Method Details

    • setupAndOpenConnection

      public static SftpConnector setupAndOpenConnection(SftpConfig config)
      Creates a new connector and immediately opens a new connection.
      Parameters:
      config - The configuration used for setting up the connection
      Returns:
      The initialized and opened sftp connection
      API Note:
      This is a convenience method to not have to call connect after initialization.
    • connect

      public void connect()
      Opens a connection to the remote SFTP server.

      Applies the following configurations:

    • disconnect

      public void disconnect()
      Closes and cleans up the connection to the remote SFTP server.

      Once disconnected, calling this method again will have no effect unless connect() is called again.