Package org.kiwiproject.jsch
Class SftpConnector
- java.lang.Object
-
- org.kiwiproject.jsch.SftpConnector
-
public class SftpConnector extends Object
A simple wrapper around aJSchinstance that handles connecting and disconnecting using the configuration specified in anSftpConfig.- Implementation Note:
- This requires JSch being available at runtime.
-
-
Constructor Summary
Constructors Constructor Description SftpConnector(com.jcraft.jsch.JSch jsch, SftpConfig config)Construct using the givenJSchandSftpConfig.SftpConnector(SftpConfig config)Construct using the givenSftpConfig.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconnect()Opens a connection to the remote SFTP server.voiddisconnect()Closes 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 Detail
-
SftpConnector
public SftpConnector(SftpConfig config)
Construct using the givenSftpConfig.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 givenJSchandSftpConfig.The instance is not connected; call
connect()to open a connection.- Parameters:
jsch- theJSchinstance to useconfig- the SFTP configuration
-
-
Method Detail
-
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:
- 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.
-
-