public class SftpSubsystem extends AbstractSftpSubsystemHelper implements Command, Runnable, SessionAware, FileSystemAware
| Modifier and Type | Field and Description |
|---|---|
protected ExitCallback |
callback |
static int |
DEFAULT_FILE_HANDLE_ROUNDS |
static int |
DEFAULT_FILE_HANDLE_SIZE |
static int |
DEFAULT_MAX_OPEN_HANDLES |
static int |
DEFAULT_MAX_READDIR_DATA_SIZE |
protected Path |
defaultDir |
protected Environment |
env |
protected OutputStream |
err |
protected ExecutorService |
executors |
protected Map<String,byte[]> |
extensions |
static String |
FILE_HANDLE_SIZE
Size in bytes of the opaque handle value
|
protected int |
fileHandleSize |
protected FileSystem |
fileSystem |
protected Map<String,Handle> |
handles |
protected InputStream |
in |
static String |
MAX_FILE_HANDLE_RAND_ROUNDS
Max. rounds to attempt to create a unique file handle - if all handles
already in use after these many rounds, then an exception is thrown
|
static int |
MAX_FILE_HANDLE_ROUNDS |
static int |
MAX_FILE_HANDLE_SIZE |
static String |
MAX_OPEN_HANDLES_PER_SESSION
Properties key for the maximum of available open handles per session.
|
static String |
MAX_READDIR_DATA_SIZE_PROP
Maximum amount of data allocated for listing the contents of a directory
in any single invocation of
doReadDir(Buffer, int) |
protected int |
maxFileHandleRounds |
static int |
MIN_FILE_HANDLE_ROUNDS |
static int |
MIN_FILE_HANDLE_SIZE |
protected OutputStream |
out |
protected Future<?> |
pendingFuture |
protected Random |
randomizer |
protected long |
requestsCount |
protected boolean |
shutdownExecutor |
protected int |
version |
protected byte[] |
workBuf |
ACL_SUPPORTED_MASK_PROP, AUTO_FOLLOW_LINKS, CLIENT_EXTENSIONS_PROP, DEFAULT_ACL_SUPPORTED_MASK, DEFAULT_AUTO_FOLLOW_LINKS, DEFAULT_MAX_READDATA_PACKET_LENGTH, DEFAULT_OPEN_SSH_EXTENSIONS, DEFAULT_OPEN_SSH_EXTENSIONS_NAMES, DEFAULT_SUPPORTED_CLIENT_EXTENSIONS, MAX_READDATA_PACKET_LENGTH_PROP, NEWLINE_VALUE, OPENSSH_EXTENSIONS_PROPlogALL_SFTP_IMPL, HIGHER_SFTP_IMPL, LOWER_SFTP_IMPL, SFTP_VERSION| Constructor and Description |
|---|
SftpSubsystem(ExecutorService executorService,
boolean shutdownOnExit,
UnsupportedAttributePolicy policy,
SftpFileSystemAccessor accessor,
SftpErrorStatusDataHandler errorStatusDataHandler) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
createLink(int id,
String existingPath,
String linkPath,
boolean symLink) |
void |
destroy()
This method is called by the SSH server to destroy the command because
the client has disconnected somehow.
|
protected void |
doBlock(int id,
String handle,
long offset,
long length,
int mask) |
protected void |
doCheckFileHash(int id,
String targetType,
String target,
Collection<String> algos,
long startOffset,
long length,
int blockSize,
Buffer buffer) |
protected void |
doClose(int id,
String handle) |
protected void |
doCopyData(int id,
String readHandle,
long readOffset,
long readLength,
String writeHandle,
long writeOffset) |
protected void |
doFSetStat(int id,
String handle,
Map<String,?> attrs) |
protected Map<String,Object> |
doFStat(int id,
String handle,
int flags) |
protected void |
doInit(Buffer buffer,
int id) |
protected byte[] |
doMD5Hash(int id,
String targetType,
String target,
long startOffset,
long length,
byte[] quickCheckHash) |
protected String |
doOpen(int id,
String path,
int pflags,
int access,
Map<String,Object> attrs) |
protected String |
doOpenDir(int id,
String path,
Path p,
LinkOption... options) |
protected void |
doOpenSSHFsync(int id,
String handle) |
protected int |
doRead(int id,
String handle,
long offset,
int length,
byte[] data,
int doff) |
protected void |
doReadDir(Buffer buffer,
int id) |
protected void |
doTextSeek(int id,
String handle,
long line) |
protected void |
doUnblock(int id,
String handle,
long offset,
long length) |
protected void |
doVersionSelect(Buffer buffer,
int id) |
protected void |
doWrite(int id,
String handle,
long offset,
int length,
byte[] data,
int doff,
int remaining) |
protected void |
executeExtendedCommand(Buffer buffer,
int id,
String extension) |
protected String |
generateFileHandle(Path file) |
Path |
getDefaultDirectory() |
ServerSession |
getServerSession() |
int |
getVersion() |
protected void |
process(Buffer buffer) |
void |
run() |
protected void |
send(Buffer buffer) |
void |
setErrorStream(OutputStream err)
Set the error stream that can be used by the shell to write its errors.
|
void |
setExitCallback(ExitCallback callback)
Set the callback that the shell has to call when it is closed.
|
void |
setFileSystem(FileSystem fileSystem)
Set the file system in which this shell will be executed.
|
void |
setInputStream(InputStream in)
Set the input stream that can be used by the shell to read input.
|
void |
setOutputStream(OutputStream out)
Set the output stream that can be used by the shell to write its output.
|
void |
setSession(ServerSession session) |
void |
start(Environment env)
Starts the command execution.
|
addMissingAttribute, addSftpEventListener, appendAclSupportedExtension, appendExtensions, appendNewlineExtension, appendOpenSSHExtensions, appendSupported2Extension, appendSupportedExtension, appendVendorIdExtension, appendVersionsExtension, 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, doRead, doReadDir, doReadLink, doReadLink, doRealPath, doRealPathV345, doRealPathV6, doRemove, doRemove, doRemove, doRemoveDirectory, doRemoveDirectory, doRename, doRename, doRename, doSetAttributes, doSetStat, doSetStat, doSpaceAvailable, doSpaceAvailable, doStat, doStat, doSymLink, doSymLink, doTextSeek, doUnblock, doWrite, getAttributes, getAttributes, getErrorStatusDataHandler, getFileSystemAccessor, getLongName, getLongName, getLongName, getPathResolutionLinkOption, getSftpEventListenerProxy, getShortName, getSupportedClientExtensions, getUnsupportedAttributePolicy, handleReadFileAttributesException, handleSetFileAttributeFailure, handleUnknownStatusFileAttributes, handleUnsupportedAttributes, handleUserPrincipalLookupServiceException, normalize, readAttrs, readFileAttributes, removeSftpEventListener, resolveAclSupportedCapabilities, resolveFile, resolveFileAttributes, resolveMissingFileAttributes, resolveMissingFileAttributeValue, resolveNewlineValue, resolveNormalizedLocation, resolveOpenSSHExtensions, sendAttrs, sendHandle, sendLink, sendPath, sendStatus, sendStatus, sendStatus, setFileAccessControl, setFileAttribute, setFileAttributes, setFileExtensions, setFileOwnership, setFilePermissions, setFileTime, toGroup, toUser, validateHandle, validateProposedVersion, validateRealPath, writeAttrs, writeDirEntrygetSimplifiedLoggerpublic static final String MAX_OPEN_HANDLES_PER_SESSION
public static final int DEFAULT_MAX_OPEN_HANDLES
public static final String FILE_HANDLE_SIZE
DEFAULT_FILE_HANDLE_SIZE,
Constant Field Valuespublic static final int MIN_FILE_HANDLE_SIZE
public static final int DEFAULT_FILE_HANDLE_SIZE
public static final int MAX_FILE_HANDLE_SIZE
public static final String MAX_FILE_HANDLE_RAND_ROUNDS
public static final int MIN_FILE_HANDLE_ROUNDS
public static final int DEFAULT_FILE_HANDLE_ROUNDS
public static final int MAX_FILE_HANDLE_ROUNDS
public static final String MAX_READDIR_DATA_SIZE_PROP
doReadDir(Buffer, int)public static final int DEFAULT_MAX_READDIR_DATA_SIZE
protected ExitCallback callback
protected InputStream in
protected OutputStream out
protected OutputStream err
protected Environment env
protected Random randomizer
protected int fileHandleSize
protected int maxFileHandleRounds
protected ExecutorService executors
protected boolean shutdownExecutor
protected Future<?> pendingFuture
protected byte[] workBuf
protected FileSystem fileSystem
protected Path defaultDir
protected long requestsCount
protected int version
public SftpSubsystem(ExecutorService executorService, boolean shutdownOnExit, UnsupportedAttributePolicy policy, SftpFileSystemAccessor accessor, SftpErrorStatusDataHandler errorStatusDataHandler)
executorService - The ExecutorService to be used by
the SftpSubsystem command when starting execution. If
null then a single-threaded ad-hoc service is used.shutdownOnExit - If true the ExecutorService.shutdownNow()
will be called when subsystem terminates - unless it is the ad-hoc
service, which will be shutdown regardlesspolicy - The UnsupportedAttributePolicy to use if failed to access
some local file attributesaccessor - The SftpFileSystemAccessor to use for opening files and directorieserrorStatusDataHandler - The (never null) SftpErrorStatusDataHandler to
use when generating failed commands error messagesThreadUtils.newSingleThreadExecutor(String)public int getVersion()
getVersion in interface SftpSubsystemEnvironmentpublic Path getDefaultDirectory()
getDefaultDirectory in interface SftpSubsystemEnvironmentchroot locationpublic void setSession(ServerSession session)
setSession in interface SessionAwaresession - The ServerSession in which this shell will be executed.public ServerSession getServerSession()
getServerSession in interface ServerSessionHolderServerSession usedpublic void setFileSystem(FileSystem fileSystem)
FileSystemAwaresetFileSystem in interface FileSystemAwarefileSystem - the file systempublic void setExitCallback(ExitCallback callback)
CommandsetExitCallback in interface Commandcallback - The ExitCallback to call when shell is closedpublic void setInputStream(InputStream in)
CommandsetInputStream in interface Commandin - The InputStream used by the shell to read input.public void setOutputStream(OutputStream out)
CommandsetOutputStream in interface Commandout - The OutputStream used by the shell to write its outputpublic void setErrorStream(OutputStream err)
CommandsetErrorStream in interface Commanderr - The OutputStream used by the shell to write its errorspublic void start(Environment env) throws IOException
CommandLifecycleRunnable,
and this method should spawn a new thread like:
Thread(this).start();
start in interface CommandLifecycleenv - The EnvironmentIOException - If failed to startprotected void process(Buffer buffer) throws IOException
process in class AbstractSftpSubsystemHelperIOExceptionprotected void executeExtendedCommand(Buffer buffer, int id, String extension) throws IOException
executeExtendedCommand in class AbstractSftpSubsystemHelperbuffer - The command Bufferid - The request idextension - The extension nameIOException - If failed to execute the extensionprotected void createLink(int id,
String existingPath,
String linkPath,
boolean symLink)
throws IOException
createLink in class AbstractSftpSubsystemHelperIOExceptionprotected void doTextSeek(int id,
String handle,
long line)
throws IOException
doTextSeek in class AbstractSftpSubsystemHelperIOExceptionprotected void doOpenSSHFsync(int id,
String handle)
throws IOException
doOpenSSHFsync in class AbstractSftpSubsystemHelperIOExceptionprotected void doCheckFileHash(int id,
String targetType,
String target,
Collection<String> algos,
long startOffset,
long length,
int blockSize,
Buffer buffer)
throws Exception
doCheckFileHash in class AbstractSftpSubsystemHelperExceptionprotected byte[] doMD5Hash(int id,
String targetType,
String target,
long startOffset,
long length,
byte[] quickCheckHash)
throws Exception
doMD5Hash in class AbstractSftpSubsystemHelperExceptionprotected void doVersionSelect(Buffer buffer, int id) throws IOException
IOExceptionprotected void doBlock(int id,
String handle,
long offset,
long length,
int mask)
throws IOException
doBlock in class AbstractSftpSubsystemHelperIOExceptionprotected void doUnblock(int id,
String handle,
long offset,
long length)
throws IOException
doUnblock in class AbstractSftpSubsystemHelperIOExceptionprotected void doCopyData(int id,
String readHandle,
long readOffset,
long readLength,
String writeHandle,
long writeOffset)
throws IOException
doCopyData in class AbstractSftpSubsystemHelperIOExceptionprotected void doReadDir(Buffer buffer, int id) throws IOException
doReadDir in class AbstractSftpSubsystemHelperIOExceptionprotected String doOpenDir(int id, String path, Path p, LinkOption... options) throws IOException
doOpenDir in class AbstractSftpSubsystemHelperIOExceptionprotected void doFSetStat(int id,
String handle,
Map<String,?> attrs)
throws IOException
doFSetStat in class AbstractSftpSubsystemHelperIOExceptionprotected Map<String,Object> doFStat(int id, String handle, int flags) throws IOException
doFStat in class AbstractSftpSubsystemHelperIOExceptionprotected void doWrite(int id,
String handle,
long offset,
int length,
byte[] data,
int doff,
int remaining)
throws IOException
doWrite in class AbstractSftpSubsystemHelperIOExceptionprotected int doRead(int id,
String handle,
long offset,
int length,
byte[] data,
int doff)
throws IOException
doRead in class AbstractSftpSubsystemHelperIOExceptionprotected void doClose(int id,
String handle)
throws IOException
doClose in class AbstractSftpSubsystemHelperIOExceptionprotected String doOpen(int id, String path, int pflags, int access, Map<String,Object> attrs) throws IOException
doOpen in class AbstractSftpSubsystemHelperid - Request idpath - Pathpflags - Open mode flags - see SSH_FXF_XXX flagsaccess - Access mode flags - see ACE4_XXX flagsattrs - Requested attributesIOException - if failed to executeprotected void doInit(Buffer buffer, int id) throws IOException
IOExceptionprotected void send(Buffer buffer) throws IOException
send in class AbstractSftpSubsystemHelperIOExceptionpublic void destroy()
CommandLifecycledestroy in interface CommandLifecycleCopyright © 2008–2018 The Apache Software Foundation. All rights reserved.