Interface SftpSession

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
MinaSftpSession

public interface SftpSession extends AutoCloseable
SFTP session interface providing secure file transfer operations. All methods throw specific SFTP exceptions instead of generic IOException for better error handling.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the SFTP session and releases resources.
    void
    delete(String path)
    Deletes a file or directory on the remote server.
    void
    download(String remote, OutputStream target)
    Downloads a remote file to the provided output stream.
    boolean
    exists(String path)
    Checks if a remote path exists.
    boolean
    Checks if a remote path is a directory.
    list(String path)
    Lists files and directories in the specified remote path.
    void
    mkdir(String path)
    Creates a directory on the remote server.
    void
    rename(String oldPath, String newPath)
    Renames or moves a file or directory on the remote server.
    long
    size(String path)
    Gets the size of a remote file.
    void
    upload(InputStream source, String remote, boolean overwrite)
    Uploads data from an input stream to a remote file.
  • Method Details

    • list

      List<SftpFile> list(String path) throws SftpException
      Lists files and directories in the specified remote path.
      Parameters:
      path - the remote path to list
      Returns:
      list of files and directories
      Throws:
      SftpException - if the operation fails
    • exists

      boolean exists(String path) throws SftpException
      Checks if a remote path exists.
      Parameters:
      path - the remote path to check
      Returns:
      true if the path exists, false otherwise
      Throws:
      SftpException - if the operation fails
    • isDirectory

      boolean isDirectory(String path) throws SftpException
      Checks if a remote path is a directory.
      Parameters:
      path - the remote path to check
      Returns:
      true if the path is a directory, false otherwise
      Throws:
      SftpException - if the operation fails
    • size

      long size(String path) throws SftpException
      Gets the size of a remote file.
      Parameters:
      path - the remote file path
      Returns:
      the file size in bytes
      Throws:
      SftpException - if the operation fails
    • download

      void download(String remote, OutputStream target) throws SftpException
      Downloads a remote file to the provided output stream.
      Parameters:
      remote - the remote file path
      target - the output stream to write to
      Throws:
      SftpException - if the download fails
    • upload

      void upload(InputStream source, String remote, boolean overwrite) throws SftpException
      Uploads data from an input stream to a remote file.
      Parameters:
      source - the input stream to read from
      remote - the remote file path
      overwrite - whether to overwrite existing files
      Throws:
      SftpException - if the upload fails
    • mkdir

      void mkdir(String path) throws SftpException
      Creates a directory on the remote server.
      Parameters:
      path - the remote directory path to create
      Throws:
      SftpException - if the operation fails
    • delete

      void delete(String path) throws SftpException
      Deletes a file or directory on the remote server.
      Parameters:
      path - the remote path to delete
      Throws:
      SftpException - if the operation fails
    • rename

      void rename(String oldPath, String newPath) throws SftpException
      Renames or moves a file or directory on the remote server.
      Parameters:
      oldPath - the current remote path
      newPath - the new remote path
      Throws:
      SftpException - if the operation fails
    • close

      void close()
      Closes the SFTP session and releases resources.
      Specified by:
      close in interface AutoCloseable