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 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
FieldsModifier and TypeFieldDescriptionprotected final org.apache.sshd.common.util.buffer.Bufferprotected ExitCallbackprotected static final org.apache.sshd.common.util.buffer.Bufferprotected final AtomicBooleanprotected Pathprotected Environmentprotected org.apache.sshd.common.util.threads.CloseableExecutorServiceprotected intprotected FileSystemprotected intprotected intprotected IoOutputStreamprotected Future<?> protected org.apache.sshd.common.random.Randomprotected final BlockingQueue<org.apache.sshd.common.util.buffer.Buffer> protected final AtomicLongprotected intprotected byte[]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_EXTENSIONSFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
ALL_SFTP_IMPL, HIGHER_SFTP_IMPL, LOWER_SFTP_IMPL, SUPPORTED_SFTP_VERSIONS -
Constructor Summary
ConstructorsConstructorDescriptionSftpSubsystem(ChannelSession channel, SftpSubsystemConfigurator configurator) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidprotected voidcreateLink(int id, String existingPath, String linkPath, boolean symLink) intdata(ChannelSession channel, byte[] buf, int start, int len) voiddestroy(ChannelSession channel) protected voidprotected 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 voidprotected voiddoCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) protected voiddoFSetStat(int id, String handle, Map<String, ?> attrs) 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 Stringprotected 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 voidprotected voiddoVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposed) protected voidprotected StringgenerateFileHandle(Path file) Generates a file handle, which is used as key in aMapto record open file handles across requests.org.apache.sshd.common.util.threads.CloseableExecutorServiceintprotected 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) voidvoidsetExitCallback(ExitCallback callback) voidsetFileSystem(FileSystem fileSystem) voidvoidvoidvoidvoidvoidstart(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, writeDirEntryMethods 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, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.sshd.common.file.FileSystemAware
setFileSystemFactoryMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContextMethods inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
getSession
-
Field Details
-
CLOSE
protected static final org.apache.sshd.common.util.buffer.Buffer CLOSE -
closed
-
requestsCount
-
extensions
-
handles
-
buffer
protected final org.apache.sshd.common.util.buffer.Buffer buffer -
requests
-
callback
-
out
-
env
-
randomizer
protected org.apache.sshd.common.random.Random randomizer -
maxHandleCount
protected int maxHandleCount -
unusedHandles
-
fileHandleSize
protected int fileHandleSize -
maxFileHandleRounds
protected int maxFileHandleRounds -
pendingFuture
-
workBuf
protected byte[] workBuf -
fileSystem
-
defaultDir
-
version
protected int version -
executorService
protected org.apache.sshd.common.util.threads.CloseableExecutorService executorService
-
-
Constructor Details
-
SftpSubsystem
- Parameters:
channel- TheChannelSessionthrough which the command was receivedconfigurator- TheSftpSubsystemConfiguratorto use
-
-
Method Details
-
resolveErrorDataChannelReceiver
protected ChannelDataReceiver resolveErrorDataChannelReceiver(ChannelSession channelSession, ChannelDataReceiver receiver) -
getVersion
public int getVersion()- Specified by:
getVersionin interfaceSftpSubsystemEnvironment- Returns:
- The negotiated version
-
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
-
getServerSession
- Specified by:
getServerSessionin interfaceServerSessionHolder
-
setFileSystem
- Specified by:
setFileSystemin interfaceorg.apache.sshd.common.file.FileSystemAware
-
setExitCallback
- Specified by:
setExitCallbackin interfaceCommand
-
setInputStream
- Specified by:
setInputStreamin interfaceCommandDirectInputStreamAware
-
setOutputStream
- Specified by:
setOutputStreamin interfaceCommandDirectOutputStreamAware
-
setErrorStream
- Specified by:
setErrorStreamin interfaceCommandDirectErrorStreamAware
-
setIoInputStream
- Specified by:
setIoInputStreamin interfaceAsyncCommandInputStreamAware
-
setIoOutputStream
- Specified by:
setIoOutputStreamin interfaceAsyncCommandOutputStreamAware
-
setIoErrorStream
- Specified by:
setIoErrorStreamin interfaceAsyncCommandErrorStreamAware
-
start
- Specified by:
startin interfaceCommandLifecycle- Throws:
IOException
-
data
- Specified by:
datain interfaceChannelDataReceiver- Throws:
IOException
-
run
public void run() -
close
- 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
- Specified by:
doTextSeekin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doOpenSSHFsync
- 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
- 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
- Specified by:
doOpenDirin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doFSetStat
- Specified by:
doFSetStatin classAbstractSftpSubsystemHelper- Throws:
IOException
-
doFStat
- 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
- 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
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
- 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
- Specified by:
sendin classAbstractSftpSubsystemHelper- Throws:
IOException
-
destroy
- Specified by:
destroyin interfaceCommandLifecycle
-
closeAllHandles
protected void closeAllHandles()
-