Package org.apache.sshd.sftp.common
Class SftpHelper
java.lang.Object
org.apache.sshd.sftp.common.SftpHelper
- Author:
- Apache MINA SSHD Project
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intattributesToPermissions(boolean isReg, boolean isDir, boolean isLnk, Collection<PosixFilePermission> perms) Converts a file / folder's attributes into a maskstatic AclEntrybuildAclEntry(int aclType, int aclFlag, int aclMask, String aclWho) static SftpClient.Attributescomplete(SftpClient.Attributes attrs, String longName) Fills in missing information in the attributes if an SFTP v3 long name is available.static AclEntryTypedecodeAclEntryType(int aclType) static Set<AclEntryFlag> decodeAclFlags(int aclFlag) static Set<AclEntryPermission> decodeAclMask(int aclMask) decodeACLs(org.apache.sshd.common.util.buffer.Buffer buffer, int version) static intReturns the equivalent SFTP value for the ACL typestatic longencodeAclFlags(Collection<AclEntryFlag> flags) static longstatic <B extends org.apache.sshd.common.util.buffer.Buffer>
BencodeACLs(B buffer, int version, Collection<AclEntry> acl) static intfileTypeFromChar(char ch) Converts a POSIX/Linux file type indicator (as if obtained by "ls -l") to a file type.static intfileTypeToPermission(int type) Converts a file type into a POSIX permission mask valuestatic booleanstatic BooleangetEndOfFileIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer, int version) Retrieves the end-of-file indicator forSSH_FXP_DATAresponses, provided the version is at least 6, and the buffer has enough available datastatic BooleangetEndOfListIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer, int version) Retrieves the end-of-list indicator forSSH_FXP_NAMEresponses, provided the version is at least 6, and the buffer has enough available datastatic StringgetLongName(String shortName, Map<String, ?> attributes) Creates an "ls -l" compatible long name stringstatic BooleanindicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer, int version, PropertyResolver resolver) Appends the end-of-list=TRUEindicator forSSH_FXP_NAMEresponses, provided the version is at least 6 and the feature is enabledstatic BooleanindicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer, int version, PropertyResolver resolver, boolean indicatorValue) Appends the end-of-list indicator forSSH_FXP_NAMEresponses, provided the version is at least 6, the feature is enabled and the indicator value is notnullstatic Set<PosixFilePermission> permissionsToAttributes(int perms) Translates a mask of permissions into its enumeration values equivalentsstatic intpermissionsToFileType(int perms) Converts a POSIX permissions mask to a file type valuereadACLs(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 FileTimereadTime(org.apache.sshd.common.util.buffer.Buffer buffer, int version, int flags) Decodes aFileTimevalue from a bufferstatic StringresolveStatusMessage(int subStatus) static intReturns 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 org.apache.sshd.common.util.buffer.Buffer>
BwriteAclEntry(B buffer, AclEntry acl) static <B extends org.apache.sshd.common.util.buffer.Buffer>
BwriteACLs(B buffer, int version, Collection<AclEntry> acl) static <B extends org.apache.sshd.common.util.buffer.Buffer>
BwriteAttributes(B buffer, SftpClient.Attributes attributes, int sftpVersion) static <B extends org.apache.sshd.common.util.buffer.Buffer>
BwriteAttrs(B buffer, int version, Map<String, ?> attributes) Writes a file / folder's attributes to a bufferstatic <B extends org.apache.sshd.common.util.buffer.Buffer>
BwriteAttrsV3(B buffer, int version, Map<String, ?> attributes) Writes the retrieved file / directory attributes in V3 formatstatic <B extends org.apache.sshd.common.util.buffer.Buffer>
BwriteAttrsV4(B buffer, int version, Map<String, ?> attributes) Writes the retrieved file / directory attributes in V4+ formatstatic <B extends org.apache.sshd.common.util.buffer.Buffer>
BwriteExtensions(B buffer, Map<?, ?> extensions) static <B extends org.apache.sshd.common.util.buffer.Buffer>
BEncodes aFileTimevalue into a buffer
-
Field Details
-
DEFAULT_SUBSTATUS_MESSAGE
-
-
Method Details
-
getEndOfFileIndicatorValue
public static Boolean getEndOfFileIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer, int version) Retrieves the end-of-file indicator forSSH_FXP_DATAresponses, provided the version is at least 6, and the buffer has enough available data- Parameters:
buffer- TheBufferto retrieve the data fromversion- The SFTP version being used- Returns:
- The indicator value -
nullif none retrieved - See Also:
-
getEndOfListIndicatorValue
public static Boolean getEndOfListIndicatorValue(org.apache.sshd.common.util.buffer.Buffer buffer, int version) Retrieves the end-of-list indicator forSSH_FXP_NAMEresponses, provided the version is at least 6, and the buffer has enough available data- Parameters:
buffer- TheBufferto retrieve the data fromversion- The SFTP version being used- Returns:
- The indicator value -
nullif none retrieved - See Also:
-
indicateEndOfNamesList
public static Boolean indicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer, int version, PropertyResolver resolver) Appends the end-of-list=TRUEindicator forSSH_FXP_NAMEresponses, provided the version is at least 6 and the feature is enabled- Parameters:
buffer- TheBufferto append the indicatorversion- The SFTP version being usedresolver- ThePropertyResolverto query whether to enable the feature- Returns:
- The actual indicator value used -
nullif none appended - See Also:
-
indicateEndOfNamesList
public static Boolean indicateEndOfNamesList(org.apache.sshd.common.util.buffer.Buffer buffer, int version, PropertyResolver resolver, boolean indicatorValue) Appends the end-of-list indicator forSSH_FXP_NAMEresponses, provided the version is at least 6, the feature is enabled and the indicator value is notnull- Parameters:
buffer- TheBufferto append the indicatorversion- The SFTP version being usedresolver- ThePropertyResolverto query whether to enable the featureindicatorValue- The indicator value -nullmeans don't append the indicator- Returns:
- The actual indicator value used -
nullif none appended - See Also:
-
writeAttrs
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttrs(B buffer, int version, Map<String, ?> attributes) Writes a file / folder's attributes to a buffer- Type Parameters:
B- Type ofBufferbeing updated- Parameters:
buffer- The target buffer instanceversion- The output encoding versionattributes- TheMapof attributes- Returns:
- The updated buffer
- See Also:
-
writeAttrsV3
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttrsV3(B buffer, int version, Map<String, ?> attributes) Writes the retrieved file / directory attributes in V3 format- Type Parameters:
B- Type ofBufferbeing updated- Parameters:
buffer- The target buffer instanceversion- The actual version - must beSftpConstants.SFTP_V3attributes- TheMapof attributes- Returns:
- The updated buffer
-
writeAttrsV4
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttrsV4(B buffer, int version, Map<String, ?> attributes) Writes the retrieved file / directory attributes in V4+ format- Type Parameters:
B- Type ofBufferbeing updated- Parameters:
buffer- The target buffer instanceversion- The actual version - must be at leastSftpConstants.SFTP_V4attributes- TheMapof attributes- Returns:
- The updated buffer
-
writeAttributes
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttributes(B buffer, SftpClient.Attributes attributes, int sftpVersion) -
getBool
- Parameters:
bool- TheBooleanvalue- Returns:
trueit the argument is non-nulland 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-trueif this is a normal fileisDir-trueif this is a directoryisLnk-trueif this is a symbolic linkperms- The file / folder's accessPosixFilePermissions- 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_xxxvalues
-
fileTypeToPermission
public static int fileTypeToPermission(int type) Converts a file type into a POSIX permission mask value- Parameters:
type- File type - seeSSH_FILEXFER_TYPE_xxxvalues- Returns:
- The matching POSIX permission mask value
-
fileTypeFromChar
public static int fileTypeFromChar(char ch) Converts a POSIX/Linux file type indicator (as if obtained by "ls -l") to a file type.- Parameters:
ch- character to convert- Returns:
- the file type
-
complete
Fills in missing information in the attributes if an SFTP v3 long name is available. If missing information cannot be extracted from the long name, it is not filled in, but no error or exception is generated.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.
- Parameters:
attrs-SftpClient.Attributesto complete, if necessarylongName- to use to find missing information, may benullor empty.- Returns:
attrs
-
permissionsToAttributes
Translates a mask of permissions into its enumeration values equivalents- Parameters:
perms- The permissions mask- Returns:
- A
Setof the equivalentPosixFilePermissions
-
resolveSubstatus
Returns the most adequate sub-status for the provided exception- Parameters:
t- The thrownThrowable- Returns:
- The matching sub-status
-
resolveStatusMessage
-
readAttrs
public static NavigableMap<String,Object> readAttrs(org.apache.sshd.common.util.buffer.Buffer buffer, int version) -
readExtensions
public static NavigableMap<String,byte[]> readExtensions(org.apache.sshd.common.util.buffer.Buffer buffer) -
writeExtensions
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeExtensions(B buffer, Map<?, ?> extensions) -
toStringExtensions
-
toBinaryExtensions
-
readACLs
-
decodeACLs
-
buildAclEntry
-
decodeAclEntryType
- Parameters:
aclType- TheACE4_ACCESS_xxx_ACE_TYPEvalue- Returns:
- The matching
AclEntryTypeornullif unknown value
-
decodeAclFlags
-
decodeAclMask
-
writeACLs
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeACLs(B buffer, int version, Collection<AclEntry> acl) -
encodeACLs
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B encodeACLs(B buffer, int version, Collection<AclEntry> acl) -
writeAclEntry
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAclEntry(B buffer, AclEntry acl) -
encodeAclEntryType
Returns the equivalent SFTP value for the ACL type- Parameters:
type- TheAclEntryType- Returns:
- The equivalent
ACE_SYSTEM_xxx_TYPEor negative ifnullor unknown type
-
encodeAclFlags
-
encodeAclMask
-
writeTime
public static <B extends org.apache.sshd.common.util.buffer.Buffer> B writeTime(B buffer, int version, int flags, FileTime time) Encodes aFileTimevalue into a buffer- Type Parameters:
B- Type ofBufferbeing 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(org.apache.sshd.common.util.buffer.Buffer buffer, int version, int flags) Decodes aFileTimevalue from a buffer- Parameters:
buffer- The sourceBufferversion- The encoding versionflags- The encoding flags- Returns:
- The decoded value
-
getLongName
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
Stringrepresenting the "long" file name as per SFTP version 3 - section 7
-