Class SftpSession
java.lang.Object
org.springframework.integration.sftp.session.SftpSession
- All Implemented Interfaces:
Closeable,AutoCloseable,Session<com.jcraft.jsch.ChannelSftp.LsEntry>
public class SftpSession extends Object implements Session<com.jcraft.jsch.ChannelSftp.LsEntry>
Default SFTP
Session implementation. Wraps a JSCH session instance.- Since:
- 2.0
- Author:
- Josh Long, Mario Gray, Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Constructor Summary
Constructors Constructor Description SftpSession(com.jcraft.jsch.Session jschSession)SftpSession(org.springframework.integration.sftp.session.JSchSessionWrapper wrapper) -
Method Summary
Modifier and Type Method Description voidappend(InputStream inputStream, String destination)Append to a file.voidclose()booleanexists(String path)Check if the remote file or directory exists.booleanfinalizeRaw()Invoke after closing the InputStream fromSession.readRaw(String).com.jcraft.jsch.ChannelSftpgetClientInstance()Get the underlying client library's client instance for this session.StringgetHostPort()Return the host:port pair this session is connected to.booleanisOpen()com.jcraft.jsch.ChannelSftp.LsEntry[]list(String path)String[]listNames(String path)booleanmkdir(String remoteDirectory)voidread(String source, OutputStream os)InputStreamreadRaw(String source)Retrieve a remote file as a rawInputStream.booleanremove(String path)voidrename(String pathFrom, String pathTo)booleanrmdir(String remoteDirectory)Remove a remote directory.voidsetChannelConnectTimeout(Duration timeout)Set the connect timeout.booleantest()Test the session is still alive, e.g.voidwrite(InputStream inputStream, String destination)
-
Constructor Details
-
SftpSession
public SftpSession(com.jcraft.jsch.Session jschSession) -
SftpSession
public SftpSession(org.springframework.integration.sftp.session.JSchSessionWrapper wrapper)
-
-
Method Details
-
setChannelConnectTimeout
Set the connect timeout.- Parameters:
timeout- the timeout to set.- Since:
- 5.2
-
remove
- Specified by:
removein interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
list
- Specified by:
listin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
listNames
- Specified by:
listNamesin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
read
- Specified by:
readin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
readRaw
Description copied from interface:SessionRetrieve a remote file as a rawInputStream.- Specified by:
readRawin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Parameters:
source- The path of the remote file.- Returns:
- The raw inputStream.
- Throws:
IOException- Any IOException.
-
finalizeRaw
public boolean finalizeRaw()Description copied from interface:SessionInvoke after closing the InputStream fromSession.readRaw(String). Required by some session providers.- Specified by:
finalizeRawin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Returns:
- true if successful.
-
write
- Specified by:
writein interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
append
Description copied from interface:SessionAppend to a file.- Specified by:
appendin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Parameters:
inputStream- the stream.destination- the destination.- Throws:
IOException- an IO Exception.
-
close
public void close() -
isOpen
public boolean isOpen() -
rename
- Specified by:
renamein interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
mkdir
- Specified by:
mkdirin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Throws:
IOException
-
rmdir
Description copied from interface:SessionRemove a remote directory.- Specified by:
rmdirin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Parameters:
remoteDirectory- The directory.- Returns:
- True if the directory was removed.
- Throws:
IOException- an IO exception.
-
exists
Description copied from interface:SessionCheck if the remote file or directory exists. -
getClientInstance
public com.jcraft.jsch.ChannelSftp getClientInstance()Description copied from interface:SessionGet the underlying client library's client instance for this session. Returns anObjectto avoid significant changes to -file, -ftp, -sftp modules, which would be required if we added another generic parameter. Implementations should narrow the return type.- Specified by:
getClientInstancein interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Returns:
- The client instance.
-
getHostPort
Description copied from interface:SessionReturn the host:port pair this session is connected to.- Specified by:
getHostPortin interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>- Returns:
- the host:port pair this session is connected to.
-
test
public boolean test()Description copied from interface:SessionTest the session is still alive, e.g. when checking out from a pool. The default implementation simply delegates toSession.isOpen().
-