Class SftpSession
java.lang.Object
org.springframework.integration.sftp.session.SftpSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
,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
ConstructorDescriptionSftpSession
(com.jcraft.jsch.Session jschSession) SftpSession
(org.springframework.integration.sftp.session.JSchSessionWrapper wrapper) -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(InputStream inputStream, String destination) Append to a file.void
close()
boolean
Check if the remote file or directory exists.boolean
Invoke after closing the InputStream fromSession.readRaw(String)
.com.jcraft.jsch.ChannelSftp
Get the underlying client library's client instance for this session.Return the host:port pair this session is connected to.boolean
isOpen()
com.jcraft.jsch.ChannelSftp.LsEntry[]
String[]
boolean
void
read
(String source, OutputStream os) Retrieve a remote file as a rawInputStream
.boolean
void
boolean
Remove a remote directory.void
setChannelConnectTimeout
(Duration timeout) Set the connect timeout.boolean
test()
Test the session is still alive, e.g.void
write
(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:
remove
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
list
- Specified by:
list
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
listNames
- Specified by:
listNames
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
readRaw
Description copied from interface:Session
Retrieve a remote file as a rawInputStream
.- Specified by:
readRaw
in 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:Session
Invoke after closing the InputStream fromSession.readRaw(String)
. Required by some session providers.- Specified by:
finalizeRaw
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Returns:
- true if successful.
-
write
- Specified by:
write
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
append
Description copied from interface:Session
Append to a file.- Specified by:
append
in 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:
rename
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
mkdir
- Specified by:
mkdir
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Throws:
IOException
-
rmdir
Description copied from interface:Session
Remove a remote directory.- Specified by:
rmdir
in 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:Session
Check if the remote file or directory exists. -
getClientInstance
public com.jcraft.jsch.ChannelSftp getClientInstance()Description copied from interface:Session
Get the underlying client library's client instance for this session. Returns anObject
to 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:
getClientInstance
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Returns:
- The client instance.
-
getHostPort
Description copied from interface:Session
Return the host:port pair this session is connected to.- Specified by:
getHostPort
in interfaceSession<com.jcraft.jsch.ChannelSftp.LsEntry>
- Returns:
- the host:port pair this session is connected to.
-
test
public boolean test()Description copied from interface:Session
Test the session is still alive, e.g. when checking out from a pool. The default implementation simply delegates toSession.isOpen()
.
-