Top Fields Constructors Methods
org.apache.sshd.sftp.server

public abstract Class AbstractSftpSubsystemHelper

extends AbstractLoggingBean
implements SftpSubsystemProxy
Class Inheritance
All Implemented Interfaces
org.apache.sshd.sftp.server.SftpSubsystemProxy, org.apache.sshd.sftp.server.SftpErrorStatusDataHandlerProvider, org.apache.sshd.sftp.server.SftpEventListenerManager, org.apache.sshd.sftp.server.SftpSubsystemEnvironment, org.apache.sshd.sftp.server.SftpUnsupportedAttributePolicyProvider, org.apache.sshd.sftp.server.SftpFileSystemAccessorProvider, org.apache.sshd.server.channel.ServerChannelSessionHolder, org.apache.sshd.server.session.ServerSessionHolder, org.apache.sshd.common.session.SessionHolder, org.apache.sshd.common.session.SessionContextHolder
Known Direct Subclasses
org.apache.sshd.sftp.server.SftpSubsystem
Annotations
@SuppressWarnings:checkstyle:MethodCount
Imports
java.io.EOFException, .File, .FileNotFoundException, .IOException, java.nio.ByteBuffer, java.nio.channels.SeekableByteChannel, java.nio.charset.StandardCharsets, java.nio.file.AccessDeniedException, .CopyOption, .FileAlreadyExistsException, .FileStore, .FileSystem, .Files, .InvalidPathException, .LinkOption, .NoSuchFileException, .NotDirectoryException, .OpenOption, .Path, .StandardCopyOption, .StandardOpenOption, java.nio.file.attribute.AclEntry, .FileTime, .GroupPrincipal, .PosixFilePermission, .UserPrincipal, java.security.Principal, java.util.AbstractMap.SimpleImmutableEntry, .ArrayList, .Arrays, .Collection, .Collections, .Comparator, .HashSet, .LinkedHashMap, .LinkedList, .List, .Map, .NavigableMap, .Objects, .Set, .TreeMap, .TreeSet, java.util.concurrent.CopyOnWriteArraySet, java.util.concurrent.atomic.AtomicReference, java.util.function.IntUnaryOperator, org.apache.sshd.common.FactoryManager, .NamedFactory, .NamedResource, .OptionalFeature, .PropertyResolver, .PropertyResolverUtils, org.apache.sshd.common.config.VersionProperties, org.apache.sshd.common.digest.BuiltinDigests, .Digest, org.apache.sshd.common.session.Session, org.apache.sshd.common.util.EventListenerUtils, .GenericUtils, .MapEntryUtils, .MapEntryUtils.MapBuilder, .MapEntryUtils.NavigableMapBuilder, .NumberUtils, .OsUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, .BufferUtils, org.apache.sshd.common.util.io.FileInfoExtractor, .IoUtils, org.apache.sshd.common.util.logging.AbstractLoggingBean, org.apache.sshd.server.channel.ChannelSession, org.apache.sshd.server.session.ServerSession, org.apache.sshd.sftp.SftpModuleProperties, org.apache.sshd.sftp.client.SftpClient, org.apache.sshd.sftp.client.extensions.openssh.OpenSSHLimitsExtensionInfo, org.apache.sshd.sftp.client.fs.WithFileAttributeCache, .WithFileAttributes, org.apache.sshd.sftp.common.SftpConstants, .SftpException, .SftpHelper, org.apache.sshd.sftp.common.extensions.AclSupportedParser, .SpaceAvailableExtensionInfo, org.apache.sshd.sftp.common.extensions.openssh.AbstractOpenSSHExtensionParser.OpenSSHExtension, .FsyncExtensionParser, .HardLinkExtensionParser, .LSetStatExtensionParser, .LimitsExtensionParser, .PosixRenameExtensionParser

Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private final ChannelSession
public static final Set<Integer>
public static final List<AbstractOpenSSHExtensionParser.OpenSSHExtension>
public static final List<String>
public static final NavigableMap<String, OptionalFeature>
DEFAULT_SUPPORTED_CLIENT_EXTENSIONS

The default reported supported client extensions (case insensitive)

private final SftpErrorStatusDataHandler
private final SftpFileSystemAccessor
private final SftpEventListener
private final Collection<SftpEventListener>
private final UnsupportedAttributePolicy
Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
log

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected NavigableMap<String, Object>
public boolean
addSftpEventListener(SftpEventListener
The SftpEventListener instance to add - never null
listener
)

Implements org.apache.sshd.sftp.server.SftpEventListenerManager.addSftpEventListener.

Register a listener instance

protected int
protected void
appendExtensions(Buffer buffer, String supportedVersions)

protected String

Returns:

The appended value
appendNewlineExtension
(Buffer
The Buffer to append to
buffer
,
ServerSession
The ServerSession for which this extension is added
session
)

Appends the "newline" extension to the buffer

Note

if overriding this method make sure you either do not append anything or use the correct extension name

protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension>
protected void
appendSupported2Extension(Buffer
The Buffer to append to
buffer
,
Collection<String>
The extra extensions that are available and can be reported - may be null/empty
extras
)

Appends the "supported2" extension to the buffer

Note

if overriding this method make sure you either do not append anything or use the correct extension name

protected void
appendSupportedExtension(Buffer
The Buffer to append to
buffer
,
Collection<String>
The extra extensions that are available and can be reported - may be null/empty
extras
)

Appends the "supported" extension to the buffer

Note

if overriding this method make sure you either do not append anything or use the correct extension name

protected Map<String, ?>

Returns:

The version properties
appendVendorIdExtension
(Buffer
The Buffer to append to
buffer
,
Map<String, ?>
The currently available version properties - ignored if null/empty. The code expects the following values:
  • groupId - as the vendor name
  • artifactId - as the product name
  • version - as the product version
versionProperties
,
ServerSession
The ServerSession for which these properties are added
session
)

Appends the "vendor-id" extension to the buffer

Note

if overriding this method make sure you either do not append anything or use the correct extension name

protected String

Returns:

The apended value
appendVersionsExtension
(Buffer
The Buffer to append to
buffer
,
String
The recommended value - ignored if null/empty
value
,
ServerSession
The ServerSession for which this extension is added
session
)

Appends the "versions" extension to the buffer

Note

if overriding this method make sure you either do not append anything or use the correct extension name

public Boolean

Returns:

whether there are symlinks in the path to this file, or null if unknown
checkSymlinkState
(Path
the file to check for symlink presence
path
,
boolean
whether to never follow symlinks in the parent paths
neverFollowSymLinks
,
LinkOption[]
whether the file itself can be a symlink
options
)

A utility function to validate that the directories leading up to a file are not symlinks

protected Map.Entry<Integer, String>

Returns:

A "pair" whose key is the negotiated version and value a String of comma separated values representing all the supported versions. null if validation failed and an appropriate status message was sent
checkVersionCompatibility
(Buffer
The Buffer containing the request
buffer
,
int
The SSH message ID to be used to send the failure message if required
id
,
int
The proposed version value
proposed
,
int
The failure opcode to send if validation fails
failureOpcode
)

Checks if a proposed version is within supported range

Note

if the user forced a specific value via the SftpModuleProperties#SFTP_VERSION property, then it is used to validate the proposed value

protected void
doBlock(Buffer buffer, int id)

protected abstract void
doBlock(int id, String handle, long offset, long length, int mask)

protected void
doCheckFileHash(Buffer buffer, int id, String targetType)

protected void
doCheckFileHash(int id, Path file, NamedFactory<? extends Digest> factory, long startOffset, long length, int blockSize, Buffer buffer)

protected abstract void
doCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, Buffer buffer)

protected void
doClose(Buffer buffer, int id)

protected abstract void
doClose(int id, String handle)

protected void
doCopyData(Buffer buffer, int id)

protected abstract void
doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset)

protected void
doCopyFile(Buffer buffer, int id)

protected void
doCopyFile(int id, String srcFile, String dstFile, boolean overwriteDestination)

protected void
doCopyFile(int id, String srcFile, String dstFile, Collection<CopyOption> opts)

protected void
doExtended(Buffer buffer, int id)

protected void
doFSetStat(Buffer buffer, int id)

protected abstract void
doFSetStat(int id, String handle, Map<String, ?> attrs)

protected void
doFStat(Buffer buffer, int id)

protected abstract Map<String, Object>
doFStat(int id, String handle, int flags)

protected abstract void
doInit(Buffer buffer, int id)

protected void
doLStat(Buffer buffer, int id)

protected Map<String, Object>
doLStat(int id, String path, int flags)

protected void
doMakeDirectory(Buffer buffer, int id)

protected void
doMakeDirectory(int id, String path, Map<String, ?> attrs)

protected void
doMD5Hash(Buffer buffer, int id, String targetType)

protected abstract byte[]
doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash)

protected byte[]
doMD5Hash(int id, Path path, long startOffset, long length, byte[] quickCheckHash)

protected void
doOpen(Buffer buffer, int id)

protected abstract String

Returns:

The assigned (opaque) handle
doOpen
(int
Request id
id
,
String
Path
path
,
int
Open mode flags - see SSH_FXF_XXX flags
pflags
,
int
Access mode flags - see ACE4_XXX flags
access
,
Map<String, Object>
Requested attributes
attrs
)

protected void
doOpenDir(Buffer buffer, int id)

protected abstract String
doOpenDir(int id, String path, Path p, LinkOption... options)

protected void
doOpenSSHFsync(Buffer buffer, int id)

protected abstract void
doOpenSSHFsync(int id, String handle)

protected void
doOpenSSHLimits(Buffer buffer, int id)

protected void
doPosixRename(Buffer buffer, int id)

protected void
doProcess(Buffer buffer, int length, int type, int id)

protected void
doRead(Buffer buffer, int id)

protected abstract int
doRead(int id, String handle, long offset, int length, byte[] data, int doff, AtomicReference<Boolean> eof)

protected abstract void
doReadDir(Buffer buffer, int id)

protected int

Returns:

Number of written entries
doReadDir
(int
Request id
id
,
String
The (opaque) handle assigned to this directory
handle
,
DirectoryHandle dir, Buffer
The Buffer to write the results
buffer
,
int
Max. buffer size
maxSize
,
boolean
Whether to follow symbolic links when querying the directory contents
followLinks
)

protected void
doRealPath(Buffer buffer, int id)

protected AbstractMap.SimpleImmutableEntry<Path, Boolean>
doRealPathV345(int id, String path, Path p, LinkOption... options)

protected AbstractMap.SimpleImmutableEntry<Path, Boolean>
doRealPathV6(int id, String path, Collection<String> extraPaths, Path p, LinkOption... options)

protected void
doRemove(int
Deletion request ID
id
,
Path
Path to delete
p
,
boolean
Whether the requested path represents a directory or a regular file
isDirectory
)

Called when need to delete a file / directory - also informs the SftpEventListener

protected void
doRemove(Buffer buffer, int id)

protected void
doRemoveDirectory(Buffer buffer, int id)

protected void
doRemoveDirectory(int id, String path)

protected void
doRemoveFile(int id, String path)

protected void
doRename(Buffer buffer, int id)

protected void
doRename(int id, String oldPath, String newPath, int flags)

protected void
doRename(int id, String oldPath, String newPath, Collection<CopyOption> opts)

protected void
doSetAttributes(int cmd, String extension, Path file, Map<String, ?> attributes, boolean followLinks)

protected void
doSetStat(Buffer buffer, int id, String extension, int cmd, Boolean followLinks)

protected void
doSetStat(int id, String path, int cmd, String extension, Map<String, ?> attrs, Boolean followLinks)

protected void
doSpaceAvailable(Buffer buffer, int id)

protected SpaceAvailableExtensionInfo
doSpaceAvailable(int id, String path)

protected void
doStat(Buffer buffer, int id)

protected Map<String, Object>
doStat(int id, String path, int flags)

protected void
doTextSeek(Buffer buffer, int id)

protected abstract void
doTextSeek(int id, String handle, long line)

protected void
doUnblock(Buffer buffer, int id)

protected abstract void
doUnblock(int id, String handle, long offset, long length)

protected void
doUnsupported(Buffer buffer, int length, int type, int id)

protected void
doUnsupportedExtension(Buffer buffer, int id, String extension)

protected void
doVersionSelect(Buffer buffer, int id)

protected abstract void
doVersionSelect(Buffer buffer, int id, String proposed)

protected void
doWrite(Buffer buffer, int id)

protected abstract void
doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining)

protected void
executeExtendedCommand(Buffer
The command Buffer
buffer
,
int
The request id
id
,
String
The extension name
extension
)

protected NavigableMap<String, Object>
getAttributes(Path file, LinkOption... options)

protected NavigableMap<String, Object>

Returns:

A Map of the retrieved attributes
getAttributes
(Path
The Path location for the required attributes
path
,
int
A mask of the original required attributes - ignored by the default implementation
flags
,
LinkOption...
The LinkOptions to use in order to access the file if necessary
options
)

public SftpErrorStatusDataHandler
public SftpFileSystemAccessor
protected String
getLongName(Path f, String shortName, LinkOption... options)

protected String
getLongName(Path f, String shortName, boolean sendAttrs, LinkOption... options)

protected String
getLongName(Path f, String shortName, Map<String, ?> attributes)

protected String
getLongName(Path f, String shortName, SftpClient.Attributes attributes)

protected OpenSSHLimitsExtensionInfo
protected LinkOption[]
getPathResolutionLinkOption(int cmd, String extension, Path path)

public ChannelSession
public SftpEventListener
protected String
protected Map<String, OptionalFeature>
public UnsupportedAttributePolicy
protected NavigableMap<String, Object>
protected void
handleSetFileAttributeFailure(Path file, String view, String attribute, Object value, Collection<String> unsupported, Exception e)

protected NavigableMap<String, Object>
handleUnknownStatusFileAttributes(Path file, int flags, LinkOption... options)

protected void
protected void
protected Path
protected abstract Buffer
protected void
process(Buffer
the buffer to process
buffer
)

Process an SFTP command.

protected Map<String, Object>
readAttrs(Buffer buffer)

protected NavigableMap<String, Object>
readFileAttributes(Path file, String view, LinkOption... options)

public boolean
protected Collection<Integer>
protected Path

Returns:

The local Path
resolveFile
(String
The remote path - separated by '/'
remotePath
)

protected NavigableMap<String, Object>
resolveFileAttributes(Path path, int flags, boolean neverFollowSymLinks, LinkOption... options)

protected NavigableMap<String, Object>

Returns:

A Map of the extra attributes whose values need to be updated in the original map

Note

it is allowed to specify values which override existing ones - the default implementation does not override values that have a non-null value

resolveMissingFileAttributes
(Path
The Path location for the required attributes
file
,
int
A mask of the original required attributes - ignored by the default implementation
flags
,
Map<String, Object>
The Map of attributes already retrieved - may be null/empty and/or unmodifiable
current
,
LinkOption...
The LinkOptions to use in order to access the file if necessary
options
)

Called by getAttributes(Path, int, LinkOption...) in order to complete any attributes that could not be retrieved via the supported file system views.

protected Object
protected String
protected Path
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension>
protected NavigableMap<String, Object>
resolveReportedFileAttributes(Path file, int flags, LinkOption... options)

protected abstract void
send(Buffer buffer)

protected void
sendAttrs(Buffer buffer, int id, Map<String, ?> attributes)

protected void
sendHandle(Buffer buffer, int id, String handle)

protected void
sendPath(Buffer buffer, int id, Path f, Map<String, ?> attrs)

protected void
sendStatus(Buffer
A Buffer to be used to build the status reply
buffer
,
int
Command identifier
id
,
Throwable
Thrown exception
e
,
int
The command that was attempted
cmd
,
Object...
The relevant command arguments - Note: provided only for logging purposes and subject to type and/or order change at any version
args
)

Invoked when an exception was thrown due to the execution of some SFTP command

protected void
sendStatus(Buffer buffer, int id, int substatus, String msg)

protected void
sendStatus(Buffer buffer, int id, int substatus, String msg, String lang)

protected void
protected void
setFileAttribute(Path file, String view, String attribute, Object value, LinkOption... options)

protected void
setFileAttributes(Path file, Map<String, ?> attributes, LinkOption... options)

protected void
setFileExtensions(Path file, Map<String, byte[]> extensions, LinkOption... options)

protected void
setFileOwnership(Path file, String attribute, Principal value, LinkOption... options)

protected void
protected void
setFileRawViewAttribute(Path file, String view, String attribute, Object value, LinkOption... options)

protected void
setFileTime(Path file, String view, String attribute, FileTime value, LinkOption... options)

protected <E extends IOException> E
signalOpenFailure(int id, String pathValue, Path path, boolean isDir, E thrown)

protected <E extends IOException> E
signalRemovalPreConditionFailure(int id, String pathValue, Path path, E thrown, boolean isRemoveDirectory)

protected GroupPrincipal
protected UserPrincipal
protected <
The generic handle type
H extends Handle
>
H

Returns:

The cast type
validateHandle
(String
The original handle id
handle
,
Handle
The resolved Handle instance
h
,
Class<H>
The expected handle type
type
)

Makes sure that the local handle is not null and of the specified type

protected Boolean

Returns:

A Boolean indicating whether to accept/reject the proposal. If null then rejection response has been sent, otherwise and appropriate response is generated
validateProposedVersion
(Buffer
The Buffer holding the request
buffer
,
int
The request id
id
,
String
The proposed value
proposal
)

protected AbstractMap.SimpleImmutableEntry<Path, Boolean>

Returns:

A SimpleImmutableEntry whose key is the absolute normalized Path and value is a Boolean indicating its status
validateRealPath
(int
The request identifier
id
,
String
The original path
path
,
Path
The resolve Path
f
,
LinkOption...
The LinkOptions to use to verify file existence and access
options
)

protected void
writeAttrs(Buffer buffer, Map<String, ?> attributes)

protected void
writeDirEntry(ServerSession session, int id, Buffer buffer, int index, Path f, String shortName, SftpClient.Attributes attributes)

protected void
writeDirEntry(int
Request id
id
,
DirectoryHandle dir, Map<String, Path>
An in / out Map for updating the written entry - key = short name, value = entry Path
entries
,
Buffer
The Buffer to write the results
buffer
,
int
Zero-based index of the entry to be written
index
,
Path
The entry Path
f
,
String
The entry short name
shortName
,
LinkOption...
The LinkOptions to use for querying the entry-s attributes
options
)

Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
debugdebugdebugdebugdebugerrorerrorerrorerrorerrorgetSimplifiedLoggerinfoinfowarnwarnwarnwarnwarnwarnwarnwarn