public class SftpSubsystem extends AbstractSftpSubsystemHelper implements Command, Runnable, FileSystemAware, ExecutorServiceCarrier, AsyncCommand, ChannelDataReceiver
| Modifier and Type | Field and Description |
|---|---|
protected Buffer |
buffer |
protected ExitCallback |
callback |
protected static Buffer |
CLOSE |
protected AtomicBoolean |
closed |
protected Path |
defaultDir |
protected Environment |
env |
protected CloseableExecutorService |
executorService |
protected Map<String,byte[]> |
extensions |
protected int |
fileHandleSize |
protected FileSystem |
fileSystem |
protected Map<String,Handle> |
handles |
protected int |
maxFileHandleRounds |
protected IoOutputStream |
out |
protected Future<?> |
pendingFuture |
protected Random |
randomizer |
protected BlockingQueue<Buffer> |
requests |
protected AtomicLong |
requestsCount |
protected int |
version |
protected byte[] |
workBuf |
DEFAULT_ACL_SUPPORTED_MASK, DEFAULT_OPEN_SSH_EXTENSIONS, DEFAULT_OPEN_SSH_EXTENSIONS_NAMES, DEFAULT_SUPPORTED_CLIENT_EXTENSIONSlogALL_SFTP_IMPL, HIGHER_SFTP_IMPL, LOWER_SFTP_IMPL, SUPPORTED_SFTP_VERSIONS| Constructor and Description |
|---|
SftpSubsystem(ChannelSession channel,
SftpSubsystemConfigurator configurator) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected void |
closeAllHandles() |
protected void |
createLink(int id,
String existingPath,
String linkPath,
boolean symLink) |
int |
data(ChannelSession channel,
byte[] buf,
int start,
int len)
Called when the server receives additional bytes from the client.
|
void |
destroy(ChannelSession channel)
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 dir,
LinkOption... options) |
protected void |
doOpenSSHFsync(int id,
String handle) |
protected void |
doProcess(Buffer buffer,
int length,
int type,
int id) |
protected int |
doRead(int id,
String handle,
long offset,
int length,
byte[] data,
int doff,
AtomicReference<Boolean> eof) |
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,
String proposed) |
protected void |
doWrite(int id,
String handle,
long offset,
int length,
byte[] data,
int doff,
int remaining) |
protected String |
generateFileHandle(Path file) |
Path |
getDefaultDirectory() |
CloseableExecutorService |
getExecutorService() |
ServerSession |
getServerSession() |
int |
getVersion() |
protected void |
initializeSessionRelatedMember(ServerSession session,
ChannelSession channel) |
protected Buffer |
prepareReply(Buffer buffer) |
protected ChannelDataReceiver |
resolveErrorDataChannelReceiver(ChannelSession channelSession,
ChannelDataReceiver receiver) |
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 |
setIoErrorStream(IoOutputStream err)
Set the error stream that can be used by the shell to write its errors.
|
void |
setIoInputStream(IoInputStream in)
Set the input stream that can be used by the shell to read input.
|
void |
setIoOutputStream(IoOutputStream out)
Set the output stream that can be used by the shell to write its output.
|
void |
setOutputStream(OutputStream out)
Set the output stream that can be used by the shell to write its output.
|
void |
start(ChannelSession channel,
Environment env)
Starts the command execution.
|
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, writeDirEntrydebug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetFileSystemFactorygetSessiongetSessionContextprotected static final Buffer CLOSE
protected final AtomicBoolean closed
protected final AtomicLong requestsCount
protected final Buffer buffer
protected final BlockingQueue<Buffer> requests
protected ExitCallback callback
protected IoOutputStream out
protected Environment env
protected Random randomizer
protected int fileHandleSize
protected int maxFileHandleRounds
protected Future<?> pendingFuture
protected byte[] workBuf
protected FileSystem fileSystem
protected Path defaultDir
protected int version
protected CloseableExecutorService executorService
public SftpSubsystem(ChannelSession channel, SftpSubsystemConfigurator configurator)
channel - The ChannelSession through which the command was receivedconfigurator - The SftpSubsystemConfigurator to useprotected ChannelDataReceiver resolveErrorDataChannelReceiver(ChannelSession channelSession, ChannelDataReceiver receiver)
public int getVersion()
getVersion in interface SftpSubsystemEnvironmentpublic Path getDefaultDirectory()
getDefaultDirectory in interface SftpSubsystemEnvironmentchroot locationpublic CloseableExecutorService getExecutorService()
getExecutorService in interface ExecutorServiceCarrierCloseableExecutorService to useprotected void initializeSessionRelatedMember(ServerSession session, ChannelSession channel)
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)
CommandDirectInputStreamAwaresetInputStream in interface CommandDirectInputStreamAwarein - The InputStream used by the shell to read input.public void setOutputStream(OutputStream out)
CommandDirectOutputStreamAwaresetOutputStream in interface CommandDirectOutputStreamAwareout - The OutputStream used by the shell to write its outputpublic void setErrorStream(OutputStream err)
CommandDirectErrorStreamAwaresetErrorStream in interface CommandDirectErrorStreamAwareerr - The OutputStream used by the shell to write its errorspublic void setIoInputStream(IoInputStream in)
AsyncCommandInputStreamAwaresetIoInputStream in interface AsyncCommandInputStreamAwarein - The IoInputStream used by the shell to read inputpublic void setIoOutputStream(IoOutputStream out)
AsyncCommandOutputStreamAwaresetIoOutputStream in interface AsyncCommandOutputStreamAwareout - The IoOutputStream used by the shell to write its outputpublic void setIoErrorStream(IoOutputStream err)
AsyncCommandErrorStreamAwaresetIoErrorStream in interface AsyncCommandErrorStreamAwareerr - The IoOutputStream used by the shell to write its errorspublic void start(ChannelSession channel, Environment env) throws IOException
CommandLifecycleRunnable, and this method should spawn a new thread like:
Thread(this).start();
start in interface CommandLifecyclechannel - The ChannelSession through which the command has been receivedenv - The EnvironmentIOException - If failed to startpublic int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException
ChannelDataReceiver
Called when the server receives additional bytes from the client. When Closeable.close()-d then indicates EOF -
The client will no longer send us any more data.
SSH channels use the windowing mechanism to perform flow control, much like TCP does. The server gives the client the initial window size, which represents the number of bytes the client can send to the server. As the server receives data, it can send a message to the client to allow it to send more data.
The return value from this method is used to control this behaviour. Intuitively speaking, the callee returns the number of bytes consumed by this method, by the time this method returns. Picture a one-way long bridge (for example Golden Gate Bridge) with toll plazas on both sides. The window size is the maximum number of cars allowed on the bridge. Here we are on the receiving end, so our job here is to count the number of cars as it leaves the bridge, and if enough of them left, we'll signal the sending end that they can let in more cars. The return value of this method counts the number of cars that are leaving in this batch.
In simple cases, where the callee has consumed the bytes before it returns, the return value must be the same value as the 'len' parameter given.
On the other hand, if the callee is queueing up the received bytes somewhere to be consumed later (for example by
another thread), then this method should return 0, for the bytes aren't really consumed yet. And when at some
later point the bytes are actually used, then you'll invoke channel.getLocalWindow().consumeAndCheck(len)
to let the channel know that bytes are consumed.
This behaviour will result in a better flow control, as the server will not allow the SSH client to overflow its buffer. If instead you always return the value passed in the 'len' parameter, the place where you are queueing up bytes may overflow.
In either case, the callee must account for every bytes it receives in this method. Returning 0 and failing to
call back channel.getLocalWindow().consumeAndCheck(len) later will dry up the window size, and eventually
the client will stop sending you any data.
In the SSH protocol, this method invocation is triggered by a SSH_MSG_CHANNEL_DATA message.
data in interface ChannelDataReceiverchannel - The caller to which this ChannelDataReceiver is assigned. Never null.buf - Holds the bytes received. This buffer belongs to the caller, and it might get reused by the
caller as soon as this method returns.start - buf[start] is the first byte that received from the client.len - the length of the bytes received. Can be zero.IOException - if failed to consume the datapublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected void doProcess(Buffer buffer, int length, int type, int id) throws IOException
doProcess in class AbstractSftpSubsystemHelperIOExceptionprotected 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, String proposed) throws IOException
doVersionSelect in class AbstractSftpSubsystemHelperIOExceptionprotected 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 dir, 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,
AtomicReference<Boolean> eof)
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 String generateFileHandle(Path file) throws IOException
IOExceptionprotected void doInit(Buffer buffer, int id) throws IOException
doInit in class AbstractSftpSubsystemHelperIOExceptionprotected Buffer prepareReply(Buffer buffer)
prepareReply in class AbstractSftpSubsystemHelperprotected void send(Buffer buffer) throws IOException
send in class AbstractSftpSubsystemHelperIOExceptionpublic void destroy(ChannelSession channel)
CommandLifecycledestroy in interface CommandLifecyclechannel - The ChannelSession through which the command has been receivedprotected void closeAllHandles()
Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.