Class SftpSession
java.lang.Object
org.springframework.integration.sftp.session.SftpSession
- All Implemented Interfaces:
Closeable,AutoCloseable,Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
public class SftpSession
extends Object
implements Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
Default SFTP
Session implementation. Wraps a MINA SSHD session instance.- Since:
- 2.0
- Author:
- Josh Long, Mario Gray, Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, Christian Tzolov, Darryl Smith
-
Constructor Summary
ConstructorsConstructorDescriptionSftpSession(org.apache.sshd.sftp.client.SftpClient sftpClient) SftpSession(org.apache.sshd.sftp.client.SftpClient sftpClient, boolean isSharedClient) Construct an instance based on aSftpClientand itssharedstatus. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(InputStream inputStream, String destination) Append to a file.voidclose()Stream<org.apache.sshd.sftp.client.SftpClient.DirEntry>booleanCheck if the remote file or directory exists.booleanInvoke after closing the InputStream fromSession.readRaw(String).org.apache.sshd.sftp.client.SftpClientGet the underlying client library's client instance for this session.Return the host:port pair this session is connected to.booleanisOpen()org.apache.sshd.sftp.client.SftpClient.DirEntry[]String[]booleanvoidread(String source, OutputStream os) Retrieve a remote file as a rawInputStream.booleanvoidbooleanRemove a remote directory.booleantest()Test the session is still alive, e.g.voidwrite(InputStream inputStream, String destination)
-
Constructor Details
-
SftpSession
public SftpSession(org.apache.sshd.sftp.client.SftpClient sftpClient) -
SftpSession
public SftpSession(org.apache.sshd.sftp.client.SftpClient sftpClient, boolean isSharedClient) Construct an instance based on aSftpClientand itssharedstatus. WhenisSharedClient == true, theclose()is void.- Parameters:
sftpClient- theSftpClientto use.isSharedClient- whether theSftpClientis shared.- Since:
- 6.3.9
-
-
Method Details
-
remove
- Specified by:
removein interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
list
- Specified by:
listin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
listNames
- Specified by:
listNamesin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
doList
public Stream<org.apache.sshd.sftp.client.SftpClient.DirEntry> doList(String path) throws IOException - Throws:
IOException
-
read
- Specified by:
readin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
readRaw
Description copied from interface:SessionRetrieve a remote file as a rawInputStream.- Specified by:
readRawin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- 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<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Returns:
- true if successful.
-
write
- Specified by:
writein interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
append
Description copied from interface:SessionAppend to a file.- Specified by:
appendin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- 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<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
mkdir
- Specified by:
mkdirin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Throws:
IOException
-
rmdir
Description copied from interface:SessionRemove a remote directory.- Specified by:
rmdirin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- 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 org.apache.sshd.sftp.client.SftpClient 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<org.apache.sshd.sftp.client.SftpClient.DirEntry>- Returns:
- The client instance.
-
getHostPort
Description copied from interface:SessionReturn the host:port pair this session is connected to.- Specified by:
getHostPortin interfaceSession<org.apache.sshd.sftp.client.SftpClient.DirEntry>- 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().
-