Package org.apache.sshd.sftp.common
Class SftpHelper
- java.lang.Object
-
- org.apache.sshd.sftp.common.SftpHelper
-
public final class SftpHelper extends Object
- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static Map<Integer,String>
DEFAULT_SUBSTATUS_MESSAGE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
attributesToPermissions(boolean isReg, boolean isDir, boolean isLnk, Collection<PosixFilePermission> perms)
Converts a file / folder's attributes into a maskstatic 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 typestatic long
encodeAclFlags(Collection<AclEntryFlag> flags)
static long
encodeAclMask(Collection<AclEntryPermission> mask)
static <B extends Buffer>
BencodeACLs(B buffer, int version, Collection<? extends AclEntry> acl)
static int
fileTypeToPermission(int type)
Converts a file type into a POSIX permission mask valuestatic boolean
getBool(Boolean bool)
static Boolean
getEndOfFileIndicatorValue(Buffer buffer, int version)
Retrieves the end-of-file indicator forSSH_FXP_DATA
responses, provided the version is at least 6, and the buffer has enough available datastatic Boolean
getEndOfListIndicatorValue(Buffer buffer, int version)
Retrieves the end-of-list indicator forSSH_FXP_NAME
responses, provided the version is at least 6, and the buffer has enough available datastatic String
getLongName(String shortName, Map<String,?> attributes)
Creates an "ls -l" compatible long name stringstatic Boolean
indicateEndOfNamesList(Buffer buffer, int version, PropertyResolver resolver)
Appends the end-of-list=TRUE
indicator forSSH_FXP_NAME
responses, provided the version is at least 6 and the feature is enabledstatic Boolean
indicateEndOfNamesList(Buffer buffer, int version, PropertyResolver resolver, boolean indicatorValue)
Appends the end-of-list indicator forSSH_FXP_NAME
responses, provided the version is at least 6, the feature is enabled and the indicator value is notnull
static Set<PosixFilePermission>
permissionsToAttributes(int perms)
Translates a mask of permissions into its enumeration values equivalentsstatic int
permissionsToFileType(int perms)
Converts a POSIX permissions mask to a file type valuestatic List<AclEntry>
readACLs(Buffer buffer, int version)
static NavigableMap<String,Object>
readAttrs(Buffer buffer, int version)
static NavigableMap<String,byte[]>
readExtensions(Buffer buffer)
static FileTime
readTime(Buffer buffer, int version, int flags)
Decodes aFileTime
value from a bufferstatic String
resolveStatusMessage(int subStatus)
static int
resolveSubstatus(Throwable t)
Returns the most adequate sub-status for the provided exceptionstatic NavigableMap<String,byte[]>
toBinaryExtensions(Map<String,String> extensions)
static NavigableMap<String,String>
toStringExtensions(Map<String,?> extensions)
static <B extends Buffer>
BwriteAclEntry(B buffer, AclEntry acl)
static <B extends Buffer>
BwriteACLs(B buffer, int version, Collection<? extends AclEntry> acl)
static <B extends Buffer>
BwriteAttrs(B buffer, int version, Map<String,?> attributes)
Writes a file / folder's attributes to a bufferstatic <B extends Buffer>
BwriteAttrsV3(B buffer, int version, Map<String,?> attributes)
Writes the retrieved file / directory attributes in V3 formatstatic <B extends Buffer>
BwriteAttrsV4(B buffer, int version, Map<String,?> attributes)
Writes the retrieved file / directory attributes in V4+ formatstatic <B extends Buffer>
BwriteExtensions(B buffer, Map<?,?> extensions)
static <B extends Buffer>
BwriteTime(B buffer, int version, int flags, FileTime time)
Encodes aFileTime
value into a buffer
-
-
-
Method Detail
-
getEndOfFileIndicatorValue
public static Boolean getEndOfFileIndicatorValue(Buffer buffer, int version)
Retrieves the end-of-file indicator forSSH_FXP_DATA
responses, provided the version is at least 6, and the buffer has enough available data- Parameters:
buffer
- TheBuffer
to retrieve the data fromversion
- The SFTP version being used- Returns:
- The indicator value -
null
if none retrieved - See Also:
- SFTP v6 - section 9.3
-
getEndOfListIndicatorValue
public static Boolean getEndOfListIndicatorValue(Buffer buffer, int version)
Retrieves the end-of-list indicator forSSH_FXP_NAME
responses, provided the version is at least 6, and the buffer has enough available data- Parameters:
buffer
- TheBuffer
to retrieve the data fromversion
- The SFTP version being used- Returns:
- The indicator value -
null
if none retrieved - See Also:
- SFTP v6 - section
9.4,
indicateEndOfNamesList(Buffer, int, PropertyResolver, boolean)
-
indicateEndOfNamesList
public static Boolean indicateEndOfNamesList(Buffer buffer, int version, PropertyResolver resolver)
Appends the end-of-list=TRUE
indicator forSSH_FXP_NAME
responses, provided the version is at least 6 and the feature is enabled- Parameters:
buffer
- TheBuffer
to append the indicatorversion
- The SFTP version being usedresolver
- ThePropertyResolver
to query whether to enable the feature- Returns:
- The actual indicator value used -
null
if none appended - See Also:
indicateEndOfNamesList(Buffer, int, PropertyResolver, boolean)
-
indicateEndOfNamesList
public static Boolean indicateEndOfNamesList(Buffer buffer, int version, PropertyResolver resolver, boolean indicatorValue)
Appends the end-of-list indicator forSSH_FXP_NAME
responses, provided the version is at least 6, the feature is enabled and the indicator value is notnull
- Parameters:
buffer
- TheBuffer
to append the indicatorversion
- The SFTP version being usedresolver
- ThePropertyResolver
to query whether to enable the featureindicatorValue
- The indicator value -null
means don't append the indicator- Returns:
- The actual indicator value used -
null
if none appended - See Also:
- SFTP v6 -
section 9.4,
SftpModuleProperties.APPEND_END_OF_LIST_INDICATOR
-
writeAttrs
public static <B extends Buffer> B writeAttrs(B buffer, int version, Map<String,?> attributes)
Writes a file / folder's attributes to a buffer- Type Parameters:
B
- Type ofBuffer
being updated- Parameters:
buffer
- The target buffer instanceversion
- The output encoding versionattributes
- TheMap
of attributes- Returns:
- The updated buffer
- See Also:
writeAttrsV3(Buffer, int, Map)
,writeAttrsV4(Buffer, int, Map)
-
writeAttrsV3
public static <B extends Buffer> B writeAttrsV3(B buffer, int version, Map<String,?> attributes)
Writes the retrieved file / directory attributes in V3 format- Type Parameters:
B
- Type ofBuffer
being updated- Parameters:
buffer
- The target buffer instanceversion
- The actual version - must beSftpConstants.SFTP_V3
attributes
- TheMap
of attributes- Returns:
- The updated buffer
-
writeAttrsV4
public static <B extends Buffer> B writeAttrsV4(B buffer, int version, Map<String,?> attributes)
Writes the retrieved file / directory attributes in V4+ format- Type Parameters:
B
- Type ofBuffer
being updated- Parameters:
buffer
- The target buffer instanceversion
- The actual version - must be at leastSftpConstants.SFTP_V4
attributes
- TheMap
of attributes- Returns:
- The updated buffer
-
getBool
public static boolean getBool(Boolean bool)
- Parameters:
bool
- TheBoolean
value- Returns:
true
it the argument is non-null
and itsBoolean.booleanValue()
istrue
-
attributesToPermissions
public static int attributesToPermissions(boolean isReg, boolean isDir, boolean isLnk, Collection<PosixFilePermission> perms)
Converts a file / folder's attributes into a mask- Parameters:
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 accessPosixFilePermission
s- Returns:
- A mask encoding the file / folder's attributes
-
permissionsToFileType
public static int permissionsToFileType(int perms)
Converts a POSIX permissions mask to a file type value- Parameters:
perms
- The POSIX permissions mask- Returns:
- The file type - see
SSH_FILEXFER_TYPE_xxx
values
-
fileTypeToPermission
public static int fileTypeToPermission(int type)
Converts a file type into a POSIX permission mask value- Parameters:
type
- File type - seeSSH_FILEXFER_TYPE_xxx
values- Returns:
- The matching POSIX permission mask value
-
permissionsToAttributes
public static Set<PosixFilePermission> permissionsToAttributes(int perms)
Translates a mask of permissions into its enumeration values equivalents- Parameters:
perms
- The permissions mask- Returns:
- A
Set
of the equivalentPosixFilePermission
s
-
resolveSubstatus
public static int resolveSubstatus(Throwable t)
Returns the most adequate sub-status for the provided exception- Parameters:
t
- The thrownThrowable
- Returns:
- The matching sub-status
-
resolveStatusMessage
public static String resolveStatusMessage(int subStatus)
-
readAttrs
public static NavigableMap<String,Object> readAttrs(Buffer buffer, int version)
-
readExtensions
public static NavigableMap<String,byte[]> readExtensions(Buffer buffer)
-
toStringExtensions
public static NavigableMap<String,String> toStringExtensions(Map<String,?> extensions)
-
toBinaryExtensions
public static NavigableMap<String,byte[]> toBinaryExtensions(Map<String,String> extensions)
-
buildAclEntry
public static AclEntry buildAclEntry(int aclType, int aclFlag, int aclMask, String aclWho)
-
decodeAclEntryType
public static AclEntryType decodeAclEntryType(int aclType)
- Parameters:
aclType
- TheACE4_ACCESS_xxx_ACE_TYPE
value- Returns:
- The matching
AclEntryType
ornull
if unknown value
-
decodeAclFlags
public static Set<AclEntryFlag> decodeAclFlags(int aclFlag)
-
decodeAclMask
public static Set<AclEntryPermission> decodeAclMask(int aclMask)
-
writeACLs
public static <B extends Buffer> B writeACLs(B buffer, int version, Collection<? extends AclEntry> acl)
-
encodeACLs
public static <B extends Buffer> B encodeACLs(B buffer, int version, Collection<? extends AclEntry> acl)
-
encodeAclEntryType
public static int encodeAclEntryType(AclEntryType type)
Returns the equivalent SFTP value for the ACL type- Parameters:
type
- TheAclEntryType
- Returns:
- The equivalent
ACE_SYSTEM_xxx_TYPE
or negative ifnull
or unknown type
-
encodeAclFlags
public static long encodeAclFlags(Collection<AclEntryFlag> flags)
-
encodeAclMask
public static long encodeAclMask(Collection<AclEntryPermission> mask)
-
writeTime
public static <B extends Buffer> B writeTime(B buffer, int version, int flags, FileTime time)
Encodes aFileTime
value into a buffer- Type Parameters:
B
- Type ofBuffer
being updated- Parameters:
buffer
- The target buffer instanceversion
- The encoding versionflags
- The encoding flagstime
- The value to encode- Returns:
- The updated buffer
-
readTime
public static FileTime readTime(Buffer buffer, int version, int flags)
Decodes aFileTime
value from a buffer- Parameters:
buffer
- The sourceBuffer
version
- The encoding versionflags
- The encoding flags- Returns:
- The decoded value
-
getLongName
public static String getLongName(String shortName, Map<String,?> attributes)
Creates an "ls -l" compatible long name string- Parameters:
shortName
- The short file name - can also be "." or ".."attributes
- The file's attributes - e.g., size, owner, permissions, etc.- Returns:
- A
String
representing the "long" file name as per SFTP version 3 - section 7
-
-