Class DefaultSftpClient

All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientChannelHolder, ClientSessionHolder, SubsystemClient, ChannelHolder, NamedResource, SessionContextHolder, SessionHolder<ClientSession>, FullAccessSftpClient, RawSftpClient, SftpClient, SftpErrorDataHandler

public class DefaultSftpClient extends AbstractSftpClient
  • Field Details

  • Constructor Details

  • Method Details

    • getVersion

      public int getVersion()
      Returns:
      The negotiated SFTP protocol version
    • getClientSession

      public ClientSession getClientSession()
      Returns:
      The underlying ClientSession used
    • getClientChannel

      public ClientChannel getClientChannel()
      Returns:
      The underlying ClientChannel used
    • getServerExtensions

      public NavigableMap<String,byte[]> getServerExtensions()
      Returns:
      An (unmodifiable) NavigableMap of the reported server extensions. where key=extension name (case insensitive)
    • getNameDecodingCharset

      public Charset getNameDecodingCharset()
      Returns:
      The (never null) Charset used to decode referenced files/folders names
      See Also:
    • setNameDecodingCharset

      public void setNameDecodingCharset(Charset nameDecodingCharset)
    • isClosing

      public boolean isClosing()
    • isOpen

      public boolean isOpen()
    • close

      public void close() throws IOException
      Throws:
      IOException
    • data

      protected int data(byte[] buf, int start, int len) throws IOException
      Receive binary data from server main stream
      Parameters:
      buf - The buffer containing the incoming data
      start - Offset in buffer to read the data
      len - Available data in buffer
      Returns:
      Actual size of received data
      Throws:
      IOException - If failed to receive incoming data
    • receive

      protected boolean receive(Buffer incoming) throws IOException
      Read SFTP packets from buffer
      Parameters:
      incoming - The received Buffer
      Returns:
      true if data from incoming buffer was processed
      Throws:
      IOException - if failed to process the buffer
      See Also:
    • process

      protected void process(Buffer incoming) throws IOException
      Process an SFTP packet
      Parameters:
      incoming - The received Buffer
      Throws:
      IOException - if failed to process the buffer
    • send

      public int send(int cmd, Buffer buffer) throws IOException
      Parameters:
      cmd - Command to send - Note: only lower 8-bits are used
      buffer - The Buffer containing the command data
      Returns:
      The assigned request id
      Throws:
      IOException - if failed to send command
    • receive

      public Buffer receive(int id) throws IOException
      Parameters:
      id - The expected request id
      Returns:
      The received response Buffer containing the request id
      Throws:
      IOException - If connection closed or interrupted
    • receive

      public Buffer receive(int id, long idleTimeout) throws IOException
      Parameters:
      id - The expected request id
      idleTimeout - The amount of time to wait for the response
      Returns:
      The received response Buffer containing the request id
      Throws:
      IOException - If connection closed or interrupted
    • receive

      public Buffer receive(int id, Duration idleTimeout) throws IOException
      Parameters:
      id - The expected request id
      idleTimeout - The amount of time to wait for the response
      Returns:
      The received response Buffer containing the request id
      Throws:
      IOException - If connection closed or interrupted
    • init

      protected void init(ClientSession session, SftpVersionSelector initialVersionSelector, Duration initializationTimeout) throws IOException
      Throws:
      IOException
    • handleInitResponse

      protected void handleInitResponse(Buffer buffer) throws IOException
      Throws:
      IOException
    • waitForInitResponse

      protected Buffer waitForInitResponse(Duration initializationTimeout) throws IOException
      Throws:
      IOException
    • negotiateVersion

      public int negotiateVersion(SftpVersionSelector selector) throws IOException
      Parameters:
      selector - The SftpVersionSelector to use - ignored if null
      Returns:
      The selected version (may be same as current)
      Throws:
      IOException - If failed to negotiate
    • createSftpChannelSubsystem

      protected ChannelSubsystem createSftpChannelSubsystem(ClientSession clientSession)