public final class SftpHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
APPEND_END_OF_LIST_INDICATOR
Used to control whether to append the end-of-list indicator for
SSH_FXP_NAME responses via
indicateEndOfNamesList(Buffer, int, PropertyResolver, Boolean)
call, as indicated by SFTP v6 - section 9.4 |
static boolean |
DEFAULT_APPEND_END_OF_LIST_INDICATOR
Default value for
APPEND_END_OF_LIST_INDICATOR if none configured |
| 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 AclEntryType |
decodeAclEntryType(int aclType) |
static Set<AclEntryFlag> |
decodeAclFlags(int aclFlag) |
static Set<AclEntryPermission> |
decodeAclMask(int aclMask) |
static List<AclEntry> |
decodeACLs(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 void |
encodeACLs(Buffer buffer,
int version,
Collection<? extends AclEntry> acl) |
static int |
fileTypeToPermission(int type)
Converts a file type into a POSIX permission mask value
|
static boolean |
getBool(Boolean bool) |
static Boolean |
getEndOfFileIndicatorValue(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(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(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(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(Buffer buffer,
int version) |
static Map<String,Object> |
readAttrs(Buffer buffer,
int version) |
static Map<String,byte[]> |
readExtensions(Buffer buffer) |
static FileTime |
readTime(Buffer buffer,
int version,
int flags)
Decodes a
FileTime value from a buffer |
static String |
resolveStatusMessage(Throwable t) |
static int |
resolveSubstatus(Throwable t)
Returns the most adequate sub-status for the provided exception
|
static Map<String,byte[]> |
toBinaryExtensions(Map<String,String> extensions) |
static Map<String,String> |
toStringExtensions(Map<String,?> extensions) |
static void |
writeAclEntry(Buffer buffer,
AclEntry acl) |
static void |
writeACLs(Buffer buffer,
int version,
Collection<? extends AclEntry> acl) |
static void |
writeAttrs(Buffer buffer,
int version,
Map<String,?> attributes)
Writes a file / folder's attributes to a buffer
|
static void |
writeAttrsV3(Buffer buffer,
int version,
Map<String,?> attributes)
Writes the retrieved file / directory attributes in V3 format
|
static void |
writeAttrsV4(Buffer buffer,
int version,
Map<String,?> attributes)
Writes the retrieved file / directory attributes in V4+ format
|
static void |
writeExtensions(Buffer buffer,
Map<?,?> extensions) |
static void |
writeTime(Buffer buffer,
int version,
int flags,
FileTime time)
Encodes a
FileTime value into a buffer |
public static final String APPEND_END_OF_LIST_INDICATOR
indicateEndOfNamesList(Buffer, int, PropertyResolver, Boolean)
call, as indicated by SFTP v6 - section 9.4public static final boolean DEFAULT_APPEND_END_OF_LIST_INDICATOR
APPEND_END_OF_LIST_INDICATOR if none configuredpublic static Boolean getEndOfFileIndicatorValue(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(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(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(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 appendedAPPEND_END_OF_LIST_INDICATOR,
DEFAULT_APPEND_END_OF_LIST_INDICATORpublic static void writeAttrs(Buffer buffer, int version, Map<String,?> attributes)
buffer - The target Bufferversion - The output encoding versionattributes - The Map of attributeswriteAttrsV3(Buffer, int, Map),
writeAttrsV4(Buffer, int, Map)public static void writeAttrsV3(Buffer buffer, int version, Map<String,?> attributes)
buffer - The target Bufferversion - The actual version - must be SftpConstants.SFTP_V3attributes - The Map of attributespublic static void writeAttrsV4(Buffer buffer, int version, Map<String,?> attributes)
buffer - The target Bufferversion - The actual version - must be at least SftpConstants.SFTP_V4attributes - The Map of attributespublic 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 Set<PosixFilePermission> permissionsToAttributes(int perms)
perms - The permissions maskSet of the equivalent PosixFilePermissionspublic static int resolveSubstatus(Throwable t)
t - The thrown Throwablepublic static Map<String,byte[]> toBinaryExtensions(Map<String,String> extensions)
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 void writeACLs(Buffer buffer, int version, Collection<? extends AclEntry> acl)
public static void encodeACLs(Buffer buffer, int version, Collection<? extends 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 void writeTime(Buffer buffer, int version, int flags, FileTime time)
FileTime value into a bufferbuffer - The target Bufferversion - The encoding versionflags - The encoding flagstime - The value to encodepublic static FileTime readTime(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 © 2008–2017 The Apache Software Foundation. All rights reserved.