public final class SftpHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static Map<Integer,String> |
DEFAULT_SUBSTATUS_MESSAGE |
| Modifier and Type | Method and Description |
|---|---|
static int |
attributesToPermissions(boolean isReg,
boolean isDir,
boolean isLnk,
Collection<PosixFilePermission> perms)
Converts a file / folder's attributes into a mask
|
static AclEntry |
buildAclEntry(int aclType,
int aclFlag,
int aclMask,
String aclWho) |
static SftpClient.Attributes |
complete(SftpClient.Attributes attrs,
String longName)
Fills in missing information in the attributes if an SFTP v3 long name is available.
|
static AclEntryType |
decodeAclEntryType(int aclType) |
static Set<AclEntryFlag> |
decodeAclFlags(int aclFlag) |
static Set<AclEntryPermission> |
decodeAclMask(int aclMask) |
static List<AclEntry> |
decodeACLs(org.apache.sshd.common.util.buffer.Buffer buffer,
int version) |
static int |
encodeAclEntryType(AclEntryType type)
Returns the equivalent SFTP value for the ACL type
|
static long |
encodeAclFlags(Collection<AclEntryFlag> flags) |
static long |
encodeAclMask(Collection<AclEntryPermission> mask) |
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
encodeACLs(B buffer,
int version,
Collection<AclEntry> acl) |
static int |
fileTypeFromChar(char ch)
Converts a POSIX/Linux file type indicator (as if obtained by "ls -l") to a file type.
|
static int |
fileTypeToPermission(int type)
Converts a file type into a POSIX permission mask value
|
static boolean |
getBool(Boolean bool) |
static Boolean |
getEndOfFileIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer,
int version)
Retrieves the end-of-file indicator for
SSH_FXP_DATA responses, provided the version is at least 6, and
the buffer has enough available data |
static Boolean |
getEndOfListIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer,
int version)
Retrieves the end-of-list indicator for
SSH_FXP_NAME responses, provided the version is at least 6, and
the buffer has enough available data |
static String |
getLongName(String shortName,
Map<String,?> attributes)
Creates an "ls -l" compatible long name string
|
static Boolean |
indicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer,
int version,
PropertyResolver resolver)
Appends the end-of-list=
TRUE indicator for SSH_FXP_NAME responses, provided the version is at
least 6 and the feature is enabled |
static Boolean |
indicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer,
int version,
PropertyResolver resolver,
boolean indicatorValue)
Appends the end-of-list indicator for
SSH_FXP_NAME responses, provided the version is at least 6, the
feature is enabled and the indicator value is not null |
static Set<PosixFilePermission> |
permissionsToAttributes(int perms)
Translates a mask of permissions into its enumeration values equivalents
|
static int |
permissionsToFileType(int perms)
Converts a POSIX permissions mask to a file type value
|
static List<AclEntry> |
readACLs(org.apache.sshd.common.util.buffer.Buffer buffer,
int version) |
static NavigableMap<String,Object> |
readAttrs(org.apache.sshd.common.util.buffer.Buffer buffer,
int version) |
static NavigableMap<String,byte[]> |
readExtensions(org.apache.sshd.common.util.buffer.Buffer buffer) |
static FileTime |
readTime(org.apache.sshd.common.util.buffer.Buffer buffer,
int version,
int flags)
Decodes a
FileTime value from a buffer |
static String |
resolveStatusMessage(int subStatus) |
static int |
resolveSubstatus(Throwable t)
Returns the most adequate sub-status for the provided exception
|
static NavigableMap<String,byte[]> |
toBinaryExtensions(Map<String,String> extensions) |
static NavigableMap<String,String> |
toStringExtensions(Map<String,?> extensions) |
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeAclEntry(B buffer,
AclEntry acl) |
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeACLs(B buffer,
int version,
Collection<AclEntry> acl) |
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeAttributes(B buffer,
SftpClient.Attributes attributes,
int sftpVersion) |
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeAttrs(B buffer,
int version,
Map<String,?> attributes)
Writes a file / folder's attributes to a buffer
|
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeAttrsV3(B buffer,
int version,
Map<String,?> attributes)
Writes the retrieved file / directory attributes in V3 format
|
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeAttrsV4(B buffer,
int version,
Map<String,?> attributes)
Writes the retrieved file / directory attributes in V4+ format
|
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeExtensions(B buffer,
Map<?,?> extensions) |
static <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeTime(B buffer,
int version,
int flags,
FileTime time)
Encodes a
FileTime value into a buffer |
public static Boolean getEndOfFileIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer, int version)
SSH_FXP_DATA responses, provided the version is at least 6, and
the buffer has enough available databuffer - The Buffer to retrieve the data fromversion - The SFTP version being usednull if none retrievedpublic static Boolean getEndOfListIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer, int version)
SSH_FXP_NAME responses, provided the version is at least 6, and
the buffer has enough available databuffer - The Buffer to retrieve the data fromversion - The SFTP version being usednull if none retrievedindicateEndOfNamesList(Buffer, int, PropertyResolver, boolean)public static Boolean indicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer, int version, PropertyResolver resolver)
TRUE indicator for SSH_FXP_NAME responses, provided the version is at
least 6 and the feature is enabledbuffer - The Buffer to append the indicatorversion - The SFTP version being usedresolver - The PropertyResolver to query whether to enable the featurenull if none appendedindicateEndOfNamesList(Buffer, int, PropertyResolver, boolean)public static Boolean indicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer, int version, PropertyResolver resolver, boolean indicatorValue)
SSH_FXP_NAME responses, provided the version is at least 6, the
feature is enabled and the indicator value is not nullbuffer - The Buffer to append the indicatorversion - The SFTP version being usedresolver - The PropertyResolver to query whether to enable the featureindicatorValue - The indicator value - null means don't append the indicatornull if none appendedSftpModuleProperties.APPEND_END_OF_LIST_INDICATORpublic static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttrs(B buffer, int version, Map<String,?> attributes)
B - Type of Buffer being updatedbuffer - The target buffer instanceversion - The output encoding versionattributes - The Map of attributeswriteAttrsV3(Buffer, int, Map),
writeAttrsV4(Buffer, int, Map)public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttrsV3(B buffer, int version, Map<String,?> attributes)
B - Type of Buffer being updatedbuffer - The target buffer instanceversion - The actual version - must be SftpConstants.SFTP_V3attributes - The Map of attributespublic static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttrsV4(B buffer, int version, Map<String,?> attributes)
B - Type of Buffer being updatedbuffer - The target buffer instanceversion - The actual version - must be at least SftpConstants.SFTP_V4attributes - The Map of attributespublic static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttributes(B buffer, SftpClient.Attributes attributes, int sftpVersion)
public static boolean getBool(Boolean bool)
bool - The Boolean valuetrue it the argument is non-null and its Boolean.booleanValue() is
truepublic static int attributesToPermissions(boolean isReg,
boolean isDir,
boolean isLnk,
Collection<PosixFilePermission> perms)
isReg - true if this is a normal fileisDir - true if this is a directoryisLnk - true if this is a symbolic linkperms - The file / folder's access PosixFilePermissionspublic static int permissionsToFileType(int perms)
perms - The POSIX permissions maskSSH_FILEXFER_TYPE_xxx valuespublic static int fileTypeToPermission(int type)
type - File type - see SSH_FILEXFER_TYPE_xxx valuespublic static int fileTypeFromChar(char ch)
ch - character to convertpublic static SftpClient.Attributes complete(SftpClient.Attributes attrs, String longName)
The SFTP draft RFC discourages parsing a long name to extract information and states the attributes should be used instead. But some SFTP v3 servers do not send all information in the attributes... for instance the SolarWinds SFTP server on Windows does not include the file type flags in the permissions. The only way to determine the file type is then to look at the permissions string in the long name.
attrs - SftpClient.Attributes to complete, if necessarylongName - to use to find missing information, may be null or empty.attrspublic static Set<PosixFilePermission> permissionsToAttributes(int perms)
perms - The permissions maskSet of the equivalent PosixFilePermissionspublic static int resolveSubstatus(Throwable t)
t - The thrown Throwablepublic static String resolveStatusMessage(int subStatus)
public static NavigableMap<String,Object> readAttrs(org.apache.sshd.common.util.buffer.Buffer buffer, int version)
public static NavigableMap<String,byte[]> readExtensions(org.apache.sshd.common.util.buffer.Buffer buffer)
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeExtensions(B buffer, Map<?,?> extensions)
public static NavigableMap<String,String> toStringExtensions(Map<String,?> extensions)
public static NavigableMap<String,byte[]> toBinaryExtensions(Map<String,String> extensions)
public static List<AclEntry> readACLs(org.apache.sshd.common.util.buffer.Buffer buffer, int version)
public static List<AclEntry> decodeACLs(org.apache.sshd.common.util.buffer.Buffer buffer, int version)
public static AclEntry buildAclEntry(int aclType, int aclFlag, int aclMask, String aclWho)
public static AclEntryType decodeAclEntryType(int aclType)
aclType - The ACE4_ACCESS_xxx_ACE_TYPE valueAclEntryType or null if unknown valuepublic static Set<AclEntryFlag> decodeAclFlags(int aclFlag)
public static Set<AclEntryPermission> decodeAclMask(int aclMask)
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeACLs(B buffer, int version, Collection<AclEntry> acl)
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B encodeACLs(B buffer, int version, Collection<AclEntry> acl)
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAclEntry(B buffer, AclEntry acl)
public static int encodeAclEntryType(AclEntryType type)
type - The AclEntryTypeACE_SYSTEM_xxx_TYPE or negative if null or unknown typepublic static long encodeAclFlags(Collection<AclEntryFlag> flags)
public static long encodeAclMask(Collection<AclEntryPermission> mask)
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeTime(B buffer, int version, int flags, FileTime time)
FileTime value into a bufferB - Type of Buffer being updatedbuffer - The target buffer instanceversion - The encoding versionflags - The encoding flagstime - The value to encodepublic static FileTime readTime(org.apache.sshd.common.util.buffer.Buffer buffer, int version, int flags)
FileTime value from a bufferbuffer - The source Bufferversion - The encoding versionflags - The encoding flagspublic static String getLongName(String shortName, Map<String,?> attributes)
shortName - The short file name - can also be "." or ".."attributes - The file's attributes - e.g., size, owner, permissions, etc.String representing the "long" file name as per
SFTP version 3 - section
7Copyright © 2018–2024 The Apache Software Foundation. All rights reserved.