Class SftpSubsystem

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.sftp.server.AbstractSftpSubsystemHelper
org.apache.sshd.sftp.server.SftpSubsystem
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable, org.apache.sshd.common.file.FileSystemAware, org.apache.sshd.common.session.SessionContextHolder, org.apache.sshd.common.session.SessionHolder<org.apache.sshd.server.session.ServerSession>, org.apache.sshd.common.util.threads.ExecutorServiceCarrier, org.apache.sshd.server.channel.ChannelDataReceiver, org.apache.sshd.server.channel.ServerChannelSessionHolder, org.apache.sshd.server.command.AsyncCommand, org.apache.sshd.server.command.AsyncCommandErrorStreamAware, org.apache.sshd.server.command.AsyncCommandInputStreamAware, org.apache.sshd.server.command.AsyncCommandOutputStreamAware, org.apache.sshd.server.command.AsyncCommandStreamsAware, org.apache.sshd.server.command.Command, org.apache.sshd.server.command.CommandDirectErrorStreamAware, org.apache.sshd.server.command.CommandDirectInputStreamAware, org.apache.sshd.server.command.CommandDirectOutputStreamAware, org.apache.sshd.server.command.CommandDirectStreamsAware, org.apache.sshd.server.command.CommandLifecycle, org.apache.sshd.server.session.ServerSessionHolder, SftpErrorStatusDataHandlerProvider, SftpEventListenerManager, SftpFileSystemAccessorProvider, SftpSubsystemEnvironment, SftpSubsystemProxy, SftpUnsupportedAttributePolicyProvider

public class SftpSubsystem extends AbstractSftpSubsystemHelper implements Runnable, org.apache.sshd.common.file.FileSystemAware, org.apache.sshd.common.util.threads.ExecutorServiceCarrier, org.apache.sshd.server.command.AsyncCommand, org.apache.sshd.server.channel.ChannelDataReceiver
SFTP subsystem
Author:
Apache MINA SSHD Project
  • Field Details

    • CLOSE

      protected static final org.apache.sshd.common.util.buffer.Buffer CLOSE
    • closed

      protected final AtomicBoolean closed
    • requestsCount

      protected final AtomicLong requestsCount
    • extensions

      protected final Map<String,byte[]> extensions
    • handles

      protected final Map<String,Handle> handles
    • buffer

      protected final org.apache.sshd.common.util.buffer.Buffer buffer
    • requests

      protected final BlockingQueue<org.apache.sshd.common.util.buffer.Buffer> requests
    • callback

      protected org.apache.sshd.server.ExitCallback callback
    • out

      protected org.apache.sshd.common.io.IoOutputStream out
    • env

      protected org.apache.sshd.server.Environment env
    • randomizer

      protected org.apache.sshd.common.random.Random randomizer
    • maxHandleCount

      protected int maxHandleCount
    • unusedHandles

      protected Deque<String> unusedHandles
    • fileHandleSize

      protected int fileHandleSize
    • maxFileHandleRounds

      protected int maxFileHandleRounds
    • pendingFuture

      protected Future<?> pendingFuture
    • workBuf

      protected byte[] workBuf
    • fileSystem

      protected FileSystem fileSystem
    • defaultDir

      protected Path defaultDir
    • version

      protected int version
    • executorService

      protected org.apache.sshd.common.util.threads.CloseableExecutorService executorService
  • Constructor Details

    • SftpSubsystem

      public SftpSubsystem(org.apache.sshd.server.channel.ChannelSession channel, SftpSubsystemConfigurator configurator)
      Parameters:
      channel - The ChannelSession through which the command was received
      configurator - The SftpSubsystemConfigurator to use
  • Method Details

    • resolveErrorDataChannelReceiver

      protected org.apache.sshd.server.channel.ChannelDataReceiver resolveErrorDataChannelReceiver(org.apache.sshd.server.channel.ChannelSession channelSession, org.apache.sshd.server.channel.ChannelDataReceiver receiver)
    • getVersion

      public int getVersion()
      Specified by:
      getVersion in interface SftpSubsystemEnvironment
      Returns:
      The negotiated version
    • getDefaultDirectory

      public Path getDefaultDirectory()
      Specified by:
      getDefaultDirectory in interface SftpSubsystemEnvironment
      Returns:
      The default root directory used to resolve relative paths - a.k.a. the chroot location
    • getExecutorService

      public org.apache.sshd.common.util.threads.CloseableExecutorService getExecutorService()
      Specified by:
      getExecutorService in interface org.apache.sshd.common.util.threads.ExecutorServiceCarrier
    • initializeSessionRelatedMember

      protected void initializeSessionRelatedMember(org.apache.sshd.server.session.ServerSession session, org.apache.sshd.server.channel.ChannelSession channel)
    • getServerSession

      public org.apache.sshd.server.session.ServerSession getServerSession()
      Specified by:
      getServerSession in interface org.apache.sshd.server.session.ServerSessionHolder
    • setFileSystem

      public void setFileSystem(FileSystem fileSystem)
      Specified by:
      setFileSystem in interface org.apache.sshd.common.file.FileSystemAware
    • setExitCallback

      public void setExitCallback(org.apache.sshd.server.ExitCallback callback)
      Specified by:
      setExitCallback in interface org.apache.sshd.server.command.Command
    • setInputStream

      public void setInputStream(InputStream in)
      Specified by:
      setInputStream in interface org.apache.sshd.server.command.CommandDirectInputStreamAware
    • setOutputStream

      public void setOutputStream(OutputStream out)
      Specified by:
      setOutputStream in interface org.apache.sshd.server.command.CommandDirectOutputStreamAware
    • setErrorStream

      public void setErrorStream(OutputStream err)
      Specified by:
      setErrorStream in interface org.apache.sshd.server.command.CommandDirectErrorStreamAware
    • setIoInputStream

      public void setIoInputStream(org.apache.sshd.common.io.IoInputStream in)
      Specified by:
      setIoInputStream in interface org.apache.sshd.server.command.AsyncCommandInputStreamAware
    • setIoOutputStream

      public void setIoOutputStream(org.apache.sshd.common.io.IoOutputStream out)
      Specified by:
      setIoOutputStream in interface org.apache.sshd.server.command.AsyncCommandOutputStreamAware
    • setIoErrorStream

      public void setIoErrorStream(org.apache.sshd.common.io.IoOutputStream err)
      Specified by:
      setIoErrorStream in interface org.apache.sshd.server.command.AsyncCommandErrorStreamAware
    • start

      public void start(org.apache.sshd.server.channel.ChannelSession channel, org.apache.sshd.server.Environment env) throws IOException
      Specified by:
      start in interface org.apache.sshd.server.command.CommandLifecycle
      Throws:
      IOException
    • data

      public int data(org.apache.sshd.server.channel.ChannelSession channel, byte[] buf, int start, int len) throws IOException
      Specified by:
      data in interface org.apache.sshd.server.channel.ChannelDataReceiver
      Throws:
      IOException
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • doProcess

      protected void doProcess(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id) throws IOException
      Overrides:
      doProcess in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • createLink

      protected void createLink(int id, String existingPath, String linkPath, boolean symLink) throws IOException
      Specified by:
      createLink in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doTextSeek

      protected void doTextSeek(int id, String handle, long line) throws IOException
      Specified by:
      doTextSeek in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doOpenSSHFsync

      protected void doOpenSSHFsync(int id, String handle) throws IOException
      Specified by:
      doOpenSSHFsync in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doCheckFileHash

      protected void doCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Specified by:
      doCheckFileHash in class AbstractSftpSubsystemHelper
      Throws:
      Exception
    • doMD5Hash

      protected byte[] doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash) throws Exception
      Specified by:
      doMD5Hash in class AbstractSftpSubsystemHelper
      Throws:
      Exception
    • doVersionSelect

      protected void doVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposed) throws IOException
      Specified by:
      doVersionSelect in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doBlock

      protected void doBlock(int id, String handle, long offset, long length, int mask) throws IOException
      Specified by:
      doBlock in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doUnblock

      protected void doUnblock(int id, String handle, long offset, long length) throws IOException
      Specified by:
      doUnblock in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doCopyData

      protected void doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) throws IOException
      Specified by:
      doCopyData in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doReadDir

      protected void doReadDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Specified by:
      doReadDir in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doOpenDir

      protected String doOpenDir(int id, String path, Path dir, LinkOption... options) throws IOException
      Specified by:
      doOpenDir in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doFSetStat

      protected void doFSetStat(int id, String handle, Map<String,?> attrs) throws IOException
      Specified by:
      doFSetStat in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doFStat

      protected Map<String,Object> doFStat(int id, String handle, int flags) throws IOException
      Specified by:
      doFStat in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doWrite

      protected void doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining) throws IOException
      Specified by:
      doWrite in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doRead

      protected int doRead(int id, String handle, long offset, int length, byte[] data, int doff, AtomicReference<Boolean> eof) throws IOException
      Specified by:
      doRead in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doClose

      protected void doClose(int id, String handle) throws IOException
      Specified by:
      doClose in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • doOpen

      protected String doOpen(int id, String path, int pflags, int access, Map<String,Object> attrs) throws IOException
      Specified by:
      doOpen in class AbstractSftpSubsystemHelper
      Parameters:
      id - Request id
      path - Path
      pflags - Open mode flags - see SSH_FXF_XXX flags
      access - Access mode flags - see ACE4_XXX flags
      attrs - Requested attributes
      Returns:
      The assigned (opaque) handle
      Throws:
      IOException - if failed to execute
    • generateFileHandle

      protected String generateFileHandle(Path file) throws IOException
      Generates a file handle, which is used as key in a Map to record open file handles across requests. For historical reasons, the handle is returned as a String, and other APIs also use String for handles, so we're kind of stuck with that.

      As of version 2.10.1, the result must be encoded using StandardCharsets.ISO_8859_1, and it must not have more than 256 IOS-8859-1 characters (i.e., bytes).

      This method is called with the monitor on the handles Map held.

      Parameters:
      file - to generate a handle for
      Returns:
      the file handle
      Throws:
      IOException - if no handle could be generated
    • doInit

      protected void doInit(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Specified by:
      doInit in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • prepareReply

      protected org.apache.sshd.common.util.buffer.Buffer prepareReply(org.apache.sshd.common.util.buffer.Buffer buffer)
      Specified by:
      prepareReply in class AbstractSftpSubsystemHelper
    • send

      protected void send(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
      Specified by:
      send in class AbstractSftpSubsystemHelper
      Throws:
      IOException
    • destroy

      public void destroy(org.apache.sshd.server.channel.ChannelSession channel)
      Specified by:
      destroy in interface org.apache.sshd.server.command.CommandLifecycle
    • closeAllHandles

      protected void closeAllHandles()