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
  • Constructor Details

    • SftpSession

      public SftpSession(org.apache.sshd.sftp.client.SftpClient sftpClient)
  • Method Details

    • remove

      public boolean remove(String path) throws IOException
      Specified by:
      remove in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Throws:
      IOException
    • list

      public org.apache.sshd.sftp.client.SftpClient.DirEntry[] list(String path) throws IOException
      Specified by:
      list in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Throws:
      IOException
    • listNames

      public String[] listNames(String path) throws IOException
      Specified by:
      listNames in interface Session<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

      public void read(String source, OutputStream os) throws IOException
      Specified by:
      read in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Throws:
      IOException
    • readRaw

      public InputStream readRaw(String source) throws IOException
      Description copied from interface: Session
      Retrieve a remote file as a raw InputStream.
      Specified by:
      readRaw in interface Session<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: Session
      Invoke after closing the InputStream from Session.readRaw(String). Required by some session providers.
      Specified by:
      finalizeRaw in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Returns:
      true if successful.
    • write

      public void write(InputStream inputStream, String destination) throws IOException
      Specified by:
      write in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Throws:
      IOException
    • append

      public void append(InputStream inputStream, String destination) throws IOException
      Description copied from interface: Session
      Append to a file.
      Specified by:
      append in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Parameters:
      inputStream - the stream.
      destination - the destination.
      Throws:
      IOException - an IO Exception.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
    • rename

      public void rename(String pathFrom, String pathTo) throws IOException
      Specified by:
      rename in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Throws:
      IOException
    • mkdir

      public boolean mkdir(String remoteDirectory) throws IOException
      Specified by:
      mkdir in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Throws:
      IOException
    • rmdir

      public boolean rmdir(String remoteDirectory) throws IOException
      Description copied from interface: Session
      Remove a remote directory.
      Specified by:
      rmdir in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Parameters:
      remoteDirectory - The directory.
      Returns:
      True if the directory was removed.
      Throws:
      IOException - an IO exception.
    • exists

      public boolean exists(String path)
      Description copied from interface: Session
      Check if the remote file or directory exists.
      Specified by:
      exists in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Parameters:
      path - the remote path.
      Returns:
      true or false if remote path exists or not.
    • getClientInstance

      public org.apache.sshd.sftp.client.SftpClient getClientInstance()
      Description copied from interface: Session
      Get the underlying client library's client instance for this session. Returns an Object 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 interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Returns:
      The client instance.
    • getHostPort

      public String getHostPort()
      Description copied from interface: Session
      Return the host:port pair this session is connected to.
      Specified by:
      getHostPort in interface Session<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: Session
      Test the session is still alive, e.g. when checking out from a pool. The default implementation simply delegates to Session.isOpen().
      Specified by:
      test in interface Session<org.apache.sshd.sftp.client.SftpClient.DirEntry>
      Returns:
      true if the test is successful.