Package org.apache.sshd.sftp.server
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,SessionContextHolder,SessionHolder<ServerSession>,org.apache.sshd.common.util.threads.ExecutorServiceCarrier,ChannelDataReceiver,ServerChannelSessionHolder,AsyncCommand,AsyncCommandErrorStreamAware,AsyncCommandInputStreamAware,AsyncCommandOutputStreamAware,AsyncCommandStreamsAware,Command,CommandDirectErrorStreamAware,CommandDirectInputStreamAware,CommandDirectOutputStreamAware,CommandDirectStreamsAware,CommandLifecycle,ServerSessionHolder,SftpErrorStatusDataHandlerProvider,SftpEventListenerManager,SftpFileSystemAccessorProvider,SftpSubsystemEnvironment,SftpSubsystemProxy,SftpUnsupportedAttributePolicyProvider
public class SftpSubsystem extends AbstractSftpSubsystemHelper implements Command, Runnable, org.apache.sshd.common.file.FileSystemAware, org.apache.sshd.common.util.threads.ExecutorServiceCarrier, AsyncCommand, ChannelDataReceiver
SFTP subsystem- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.sshd.common.util.buffer.Bufferbufferprotected ExitCallbackcallbackprotected static org.apache.sshd.common.util.buffer.BufferCLOSEprotected AtomicBooleanclosedprotected PathdefaultDirprotected Environmentenvprotected org.apache.sshd.common.util.threads.CloseableExecutorServiceexecutorServiceprotected Map<String,byte[]>extensionsprotected intfileHandleSizeprotected FileSystemfileSystemprotected Map<String,Handle>handlesprotected intmaxFileHandleRoundsprotected intmaxHandleCountprotected IoOutputStreamoutprotected Future<?>pendingFutureprotected org.apache.sshd.common.random.Randomrandomizerprotected BlockingQueue<org.apache.sshd.common.util.buffer.Buffer>requestsprotected AtomicLongrequestsCountprotected Deque<String>unusedHandlesprotected intversionprotected byte[]workBuf-
Fields inherited from class org.apache.sshd.sftp.server.AbstractSftpSubsystemHelper
DEFAULT_ACL_SUPPORTED_MASK, DEFAULT_OPEN_SSH_EXTENSIONS, DEFAULT_OPEN_SSH_EXTENSIONS_NAMES, DEFAULT_SUPPORTED_CLIENT_EXTENSIONS
-
Fields inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
ALL_SFTP_IMPL, HIGHER_SFTP_IMPL, LOWER_SFTP_IMPL, SUPPORTED_SFTP_VERSIONS
-
-
Constructor Summary
Constructors Constructor Description SftpSubsystem(ChannelSession channel, SftpSubsystemConfigurator configurator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voidcloseAllHandles()protected voidcreateLink(int id, String existingPath, String linkPath, boolean symLink)intdata(ChannelSession channel, byte[] buf, int start, int len)voiddestroy(ChannelSession channel)protected voiddoBlock(int id, String handle, long offset, long length, int mask)protected voiddoCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, org.apache.sshd.common.util.buffer.Buffer buffer)protected voiddoClose(int id, String handle)protected voiddoCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset)protected voiddoFSetStat(int id, String handle, Map<String,?> attrs)protected Map<String,Object>doFStat(int id, String handle, int flags)protected voiddoInit(org.apache.sshd.common.util.buffer.Buffer buffer, int id)protected byte[]doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash)protected StringdoOpen(int id, String path, int pflags, int access, Map<String,Object> attrs)protected StringdoOpenDir(int id, String path, Path dir, LinkOption... options)protected voiddoOpenSSHFsync(int id, String handle)protected voiddoProcess(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id)protected intdoRead(int id, String handle, long offset, int length, byte[] data, int doff, AtomicReference<Boolean> eof)protected voiddoReadDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id)protected voiddoTextSeek(int id, String handle, long line)protected voiddoUnblock(int id, String handle, long offset, long length)protected voiddoVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposed)protected voiddoWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining)protected StringgenerateFileHandle(Path file)Generates a file handle, which is used as key in aMapto record open file handles across requests.PathgetDefaultDirectory()org.apache.sshd.common.util.threads.CloseableExecutorServicegetExecutorService()ServerSessiongetServerSession()intgetVersion()protected voidinitializeSessionRelatedMember(ServerSession session, ChannelSession channel)protected org.apache.sshd.common.util.buffer.BufferprepareReply(org.apache.sshd.common.util.buffer.Buffer buffer)protected ChannelDataReceiverresolveErrorDataChannelReceiver(ChannelSession channelSession, ChannelDataReceiver receiver)voidrun()protected voidsend(org.apache.sshd.common.util.buffer.Buffer buffer)voidsetErrorStream(OutputStream err)voidsetExitCallback(ExitCallback callback)voidsetFileSystem(FileSystem fileSystem)voidsetInputStream(InputStream in)voidsetIoErrorStream(IoOutputStream err)voidsetIoInputStream(IoInputStream in)voidsetIoOutputStream(IoOutputStream out)voidsetOutputStream(OutputStream out)voidstart(ChannelSession channel, Environment env)-
Methods inherited from class org.apache.sshd.sftp.server.AbstractSftpSubsystemHelper
addMissingAttribute, addSftpEventListener, appendAclSupportedExtension, appendExtensions, appendNewlineExtension, appendOpenSSHExtensions, appendSupported2Extension, appendSupportedExtension, appendVendorIdExtension, appendVersionsExtension, checkSymlinkState, checkVersionCompatibility, doBlock, doCheckFileHash, doCheckFileHash, doClose, doCopyData, doCopyFile, doCopyFile, doCopyFile, doExtended, doFSetStat, doFStat, doLink, doLink, doLStat, doLStat, doMakeDirectory, doMakeDirectory, doMD5Hash, doMD5Hash, doOpen, doOpenDir, doOpenSSHFsync, doOpenSSHHardLink, doOpenSSHHardLink, doOpenSSHLimits, doPosixRename, doRead, doReadDir, doReadLink, doReadLink, doRealPath, doRealPathV345, doRealPathV6, doRemove, doRemove, doRemoveDirectory, doRemoveDirectory, doRemoveFile, doRename, doRename, doRename, doSetAttributes, doSetStat, doSetStat, doSpaceAvailable, doSpaceAvailable, doStat, doStat, doSymLink, doSymLink, doTextSeek, doUnblock, doUnsupported, doUnsupportedExtension, doVersionSelect, doWrite, executeExtendedCommand, getAttributes, getAttributes, getErrorStatusDataHandler, getFileSystemAccessor, getLongName, getLongName, getLongName, getLongName, getOpenSSHLimitsExtensionInfo, getPathResolutionLinkOption, getServerChannelSession, getSftpEventListenerProxy, getShortName, getSupportedClientExtensions, getUnsupportedAttributePolicy, handleReadFileAttributesException, handleSetFileAttributeFailure, handleUnknownStatusFileAttributes, handleUnsupportedAttributes, handleUserPrincipalLookupServiceException, normalize, process, readAttrs, readFileAttributes, removeSftpEventListener, resolveAclSupportedCapabilities, resolveFile, resolveFileAttributes, resolveMissingFileAttributes, resolveMissingFileAttributeValue, resolveNewlineValue, resolveNormalizedLocation, resolveOpenSSHExtensions, resolvePathResolutionFollowLinks, resolveReportedFileAttributes, sendAttrs, sendHandle, sendLink, sendPath, sendStatus, sendStatus, sendStatus, setFileAccessControl, setFileAttribute, setFileAttributes, setFileExtensions, setFileOwnership, setFilePermissions, setFileRawViewAttribute, setFileTime, signalOpenFailure, signalRemovalPreConditionFailure, toGroup, toUser, validateHandle, validateParentExistWithNoSymlinksIfNeverFollowSymlinks, validateProposedVersion, validateRealPath, writeAttrs, writeDirEntry, writeDirEntry
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
Methods inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
getSession
-
-
-
-
Field Detail
-
CLOSE
protected static final org.apache.sshd.common.util.buffer.Buffer CLOSE
-
closed
protected final AtomicBoolean closed
-
requestsCount
protected final AtomicLong requestsCount
-
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 ExitCallback callback
-
out
protected IoOutputStream out
-
env
protected Environment env
-
randomizer
protected org.apache.sshd.common.random.Random randomizer
-
maxHandleCount
protected int maxHandleCount
-
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 Detail
-
SftpSubsystem
public SftpSubsystem(ChannelSession channel, SftpSubsystemConfigurator configurator)
- Parameters:
channel- TheChannelSessionthrough which the command was receivedconfigurator- TheSftpSubsystemConfiguratorto use
-
-
Method Detail
-
resolveErrorDataChannelReceiver
protected ChannelDataReceiver resolveErrorDataChannelReceiver(ChannelSession channelSession, ChannelDataReceiver receiver)
-
getVersion
public int getVersion()
- Specified by:
getVersionin interfaceSftpSubsystemEnvironment- Returns:
- The negotiated version
-
getDefaultDirectory
public Path getDefaultDirectory()
- Specified by:
getDefaultDirectoryin interfaceSftpSubsystemEnvironment- Returns:
- The default root directory used to resolve relative paths - a.k.a. the
chrootlocation
-
getExecutorService
public org.apache.sshd.common.util.threads.CloseableExecutorService getExecutorService()
- Specified by:
getExecutorServicein interfaceorg.apache.sshd.common.util.threads.ExecutorServiceCarrier
-
initializeSessionRelatedMember
protected void initializeSessionRelatedMember(ServerSession session, ChannelSession channel)
-
getServerSession
public ServerSession getServerSession()
- Specified by:
getServerSessionin interfaceServerSessionHolder
-
setFileSystem
public void setFileSystem(FileSystem fileSystem)
- Specified by:
setFileSystemin interfaceorg.apache.sshd.common.file.FileSystemAware
-
setExitCallback
public void setExitCallback(ExitCallback callback)
- Specified by:
setExitCallbackin interfaceCommand
-
setInputStream
public void setInputStream(InputStream in)
- Specified by:
setInputStreamin interfaceCommandDirectInputStreamAware
-
setOutputStream
public void setOutputStream(OutputStream out)
- Specified by:
setOutputStreamin interfaceCommandDirectOutputStreamAware
-
setErrorStream
public void setErrorStream(OutputStream err)
- Specified by:
setErrorStreamin interfaceCommandDirectErrorStreamAware
-
setIoInputStream
public void setIoInputStream(IoInputStream in)
- Specified by:
setIoInputStreamin interfaceAsyncCommandInputStreamAware
-
setIoOutputStream
public void setIoOutputStream(IoOutputStream out)
- Specified by:
setIoOutputStreamin interfaceAsyncCommandOutputStreamAware
-
setIoErrorStream
public void setIoErrorStream(IoOutputStream err)
- Specified by:
setIoErrorStreamin interfaceAsyncCommandErrorStreamAware
-
start
public void start(ChannelSession channel, Environment env) throws IOException
- Specified by:
startin interfaceCommandLifecycle- Throws:
IOException
-
data
public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException
- Specified by:
datain interfaceChannelDataReceiver- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
doProcess
protected void doProcess(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id) throws IOException- Overrides:
doProcessin classAbstractSftpSubsystemHelper- Throws:
IOException
-
createLink
protected void createLink(int id, String existingPath, String linkPath, boolean symLink) throws IOException- Specified by:
createLinkin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doTextSeek
protected void doTextSeek(int id, String handle, long line) throws IOException- Specified by:
doTextSeekin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doOpenSSHFsync
protected void doOpenSSHFsync(int id, String handle) throws IOException- Specified by:
doOpenSSHFsyncin classAbstractSftpSubsystemHelper- 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:
doCheckFileHashin classAbstractSftpSubsystemHelper- Throws:
Exception
-
doMD5Hash
protected byte[] doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash) throws Exception- Specified by:
doMD5Hashin classAbstractSftpSubsystemHelper- Throws:
Exception
-
doVersionSelect
protected void doVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposed) throws IOException- Specified by:
doVersionSelectin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doBlock
protected void doBlock(int id, String handle, long offset, long length, int mask) throws IOException- Specified by:
doBlockin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doUnblock
protected void doUnblock(int id, String handle, long offset, long length) throws IOException- Specified by:
doUnblockin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doCopyData
protected void doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) throws IOException- Specified by:
doCopyDatain classAbstractSftpSubsystemHelper- Throws:
IOException
-
doReadDir
protected void doReadDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException- Specified by:
doReadDirin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doOpenDir
protected String doOpenDir(int id, String path, Path dir, LinkOption... options) throws IOException
- Specified by:
doOpenDirin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doFSetStat
protected void doFSetStat(int id, String handle, Map<String,?> attrs) throws IOException- Specified by:
doFSetStatin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doFStat
protected Map<String,Object> doFStat(int id, String handle, int flags) throws IOException
- Specified by:
doFStatin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doWrite
protected void doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining) throws IOException- Specified by:
doWritein classAbstractSftpSubsystemHelper- 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:
doReadin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doClose
protected void doClose(int id, String handle) throws IOException- Specified by:
doClosein classAbstractSftpSubsystemHelper- Throws:
IOException
-
doOpen
protected String doOpen(int id, String path, int pflags, int access, Map<String,Object> attrs) throws IOException
- Specified by:
doOpenin classAbstractSftpSubsystemHelper- Parameters:
id- Request idpath- Pathpflags- Open mode flags - seeSSH_FXF_XXXflagsaccess- Access mode flags - seeACE4_XXXflagsattrs- 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 aMapto record open file handles across requests. For historical reasons, the handle is returned as aString, and other APIs also useStringfor 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
handlesMapheld.- 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:
doInitin classAbstractSftpSubsystemHelper- Throws:
IOException
-
prepareReply
protected org.apache.sshd.common.util.buffer.Buffer prepareReply(org.apache.sshd.common.util.buffer.Buffer buffer)
- Specified by:
prepareReplyin classAbstractSftpSubsystemHelper
-
send
protected void send(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException- Specified by:
sendin classAbstractSftpSubsystemHelper- Throws:
IOException
-
destroy
public void destroy(ChannelSession channel)
- Specified by:
destroyin interfaceCommandLifecycle
-
closeAllHandles
protected void closeAllHandles()
-
-