Package org.kiwiproject.jsch
Class SftpConnector
java.lang.Object
org.kiwiproject.jsch.SftpConnector
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 Summary
ConstructorsConstructorDescriptionSftpConnector(com.jcraft.jsch.JSch jsch, SftpConfig config) Construct using the givenJSchandSftpConfig.SftpConnector(SftpConfig config) Construct using the givenSftpConfig. -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Opens a connection to the remote SFTP server.voidCloses and cleans up the connection to the remote SFTP server.static SftpConnectorsetupAndOpenConnection(SftpConfig config) Creates a new connector and immediately opens a new connection.
-
Constructor Details
-
SftpConnector
Construct using the givenSftpConfig.The instance is not connected; call
connect()to open a connection.- Parameters:
config- the SFTP configuration
-
SftpConnector
Construct using the givenJSchandSftpConfig.The instance is not connected; call
connect()to open a connection.- Parameters:
jsch- theJSchinstance to useconfig- the SFTP configuration
-
-
Method Details
-
setupAndOpenConnection
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:
- Known hosts (
JSch.setKnownHosts(String)) - User, host, and port (to create a
SessionviaJSch.getSession(String, String, int)) - Session timeout (
Session.setTimeout(int) - PreferredAuthentications (via
Session.setConfig(String, String)) - Key exchange type (detected from known hosts, see
KiwiJSchHelpers - Private key or password (
JSch.addIdentity(String)orSession.setPassword(String) - Enable/disable StrictHostKeyChecking (via
Session.setConfig(String, String), default is enabled)
- Known hosts (
-
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.
-