com.maverick.sshd.sftp
Class SftpFileAttributes

java.lang.Object
  extended by com.maverick.sshd.sftp.SftpFileAttributes

public class SftpFileAttributes
extends Object

This class represents the ATTRS structure defined in the draft-ietf-secsh-filexfer-02.txt which is used by the protocol to store file attribute information.

Author:
Lee David Painter

Field Summary
static int S_IFBLK
          Permissions flag: Identifies the file as a block special file
static int S_IFCHR
          Permissions flag: Identifies the file as a character device
static int S_IFDIR
          Permissions flag: Identifies the file as a directory
static int S_IFIFO
          Permissions flag: Identifies the file as a pipe
static int S_IFLNK
          Permissions flag: Identifies the file as a symbolic link
static int S_IFMT
          Permissions flag: Format mask constant can be used to mask off a file type from the mode.
static int S_IFREG
          Permissions flag: Identifies the file as a regular file
static int S_IFSOCK
          Permissions flag: Identifies the file as a socket
static int S_IRGRP
          Permissions flag: Permits a file's group to read the file.
static int S_IROTH
          Permissions flag: Permits others to read the file.
static int S_IRUSR
          Permissions flag: Permits the owner of a file to read the file.
static int S_ISGID
          Permissions flag: Bit to determine whether a file is executed as the group owner
static int S_ISUID
          Permissions flag: Bit to determine whether a file is executed as the owner
static int S_IWGRP
          Permissions flag: Permits a file's group to write to the file.
static int S_IWOTH
          Permissions flag: Permits others to write to the file.
static int S_IWUSR
          Permissions flag: Permits the owner of a file to write to the file.
static int S_IXGRP
          Permissions flag: Permits a file's group to execute the file or to search the file's directory.
static int S_IXOTH
          Permissions flag: Permits others to execute the file or to search the file's directory.
static int S_IXUSR
          Permissions flag: Permits the owner of a file to execute the file or to search the file's directory.
static int S_MODE_MASK
           
static int SSH_FILEXFER_TYPE_DIRECTORY
           
static int SSH_FILEXFER_TYPE_REGULAR
           
static int SSH_FILEXFER_TYPE_SPECIAL
           
static int SSH_FILEXFER_TYPE_SYMLINK
           
static int SSH_FILEXFER_TYPE_UNKNOWN
           
 
Constructor Summary
SftpFileAttributes()
          Creates a new FileAttributes object.
SftpFileAttributes(int version, String charset, com.maverick.util.ByteArrayReader bar)
           
 
Method Summary
 com.maverick.util.UnsignedInteger64 getAccessedTime()
          Get the last accessed time.
 Map getExtendedAttributes()
          Get the extended attributes.
 String getGID()
          Get the GID of this file.
 String getMaskString()
          Return the UNIX style mode mask
 com.maverick.util.UnsignedInteger64 getModifiedTime()
          Get the last modified time.
 com.maverick.util.UnsignedInteger32 getPermissions()
          Get the current permissions value.
 String getPermissionsString()
          Returns a formatted permissions string.
 com.maverick.util.UnsignedInteger64 getSize()
          Get the size of the file.
 String getUID()
          Get the UID of the owner.
 boolean hasAccessedTime()
          Get if the file has a last accessed time.
 boolean hasGID()
           
 boolean hasModifiedTime()
          Get if the file has a last modified time.
 boolean hasPermissions()
           
 boolean hasSize()
           
 boolean hasUID()
          Get if this file has a username associated with it.
 boolean isBlock()
          Determine whether these attributes refer to a block special file.
 boolean isCharacter()
          Determine whether these attributes refer to a character device.
 boolean isDirectory()
          Determine whether these attributes refer to a directory
 boolean isFifo()
          Determine whether these attributes refer to a pipe.
 boolean isFile()
          Determine whether these attributes refer to a file.
 boolean isFlagSet(long flag)
          Determine if a permissions flag is set.
 boolean isLink()
          Determine whether these attributes refer to a symbolic link.
 boolean isSocket()
          Determine whether these attributes refer to a socket.
 void removeExtendedAttribute(String attrName)
          Set a single extended attribute value.
 void setExtendedAttribute(String attrName, String attrValue)
          Set a single extended attribute value.
 void setExtendedAttributes(Map attributes)
          Set all the extended attributes.
 void setGID(String gid)
          Set the GID of this file.
 void setPermissions(String newPermissions)
          Set the permissions from a string in the format "rwxr-xr-x"
 void setPermissions(com.maverick.util.UnsignedInteger32 permissions)
          Set the permissions of the file.
 void setPermissionsFromMaskString(String mask)
          Set permissions given a UNIX style mask, for example '0644'
 void setPermissionsFromUmaskString(String umask)
          Set the permissions given a UNIX style umask, for example '0022' will result in 0022 ^ 0777.
 void setSize(com.maverick.util.UnsignedInteger64 size)
          Set the size of the file.
 void setTimes(com.maverick.util.UnsignedInteger64 atime, com.maverick.util.UnsignedInteger64 mtime)
          Set the last access and last modified times.
 void setType(int type)
           
 void setUID(String uid)
          Set the UID of the owner.
 byte[] toByteArray(int version)
          Returns a formatted byte array suitable for encoding into SFTP subsystem messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SSH_FILEXFER_TYPE_REGULAR

public static final int SSH_FILEXFER_TYPE_REGULAR
See Also:
Constant Field Values

SSH_FILEXFER_TYPE_DIRECTORY

public static final int SSH_FILEXFER_TYPE_DIRECTORY
See Also:
Constant Field Values

SSH_FILEXFER_TYPE_SYMLINK

public static final int SSH_FILEXFER_TYPE_SYMLINK
See Also:
Constant Field Values

SSH_FILEXFER_TYPE_SPECIAL

public static final int SSH_FILEXFER_TYPE_SPECIAL
See Also:
Constant Field Values

SSH_FILEXFER_TYPE_UNKNOWN

public static final int SSH_FILEXFER_TYPE_UNKNOWN
See Also:
Constant Field Values

S_IFMT

public static final int S_IFMT
Permissions flag: Format mask constant can be used to mask off a file type from the mode.

See Also:
Constant Field Values

S_MODE_MASK

public static final int S_MODE_MASK
See Also:
Constant Field Values

S_IFSOCK

public static final int S_IFSOCK
Permissions flag: Identifies the file as a socket

See Also:
Constant Field Values

S_IFLNK

public static final int S_IFLNK
Permissions flag: Identifies the file as a symbolic link

See Also:
Constant Field Values

S_IFREG

public static final int S_IFREG
Permissions flag: Identifies the file as a regular file

See Also:
Constant Field Values

S_IFBLK

public static final int S_IFBLK
Permissions flag: Identifies the file as a block special file

See Also:
Constant Field Values

S_IFDIR

public static final int S_IFDIR
Permissions flag: Identifies the file as a directory

See Also:
Constant Field Values

S_IFCHR

public static final int S_IFCHR
Permissions flag: Identifies the file as a character device

See Also:
Constant Field Values

S_IFIFO

public static final int S_IFIFO
Permissions flag: Identifies the file as a pipe

See Also:
Constant Field Values

S_ISUID

public static final int S_ISUID
Permissions flag: Bit to determine whether a file is executed as the owner

See Also:
Constant Field Values

S_ISGID

public static final int S_ISGID
Permissions flag: Bit to determine whether a file is executed as the group owner

See Also:
Constant Field Values

S_IRUSR

public static final int S_IRUSR
Permissions flag: Permits the owner of a file to read the file.

See Also:
Constant Field Values

S_IWUSR

public static final int S_IWUSR
Permissions flag: Permits the owner of a file to write to the file.

See Also:
Constant Field Values

S_IXUSR

public static final int S_IXUSR
Permissions flag: Permits the owner of a file to execute the file or to search the file's directory.

See Also:
Constant Field Values

S_IRGRP

public static final int S_IRGRP
Permissions flag: Permits a file's group to read the file.

See Also:
Constant Field Values

S_IWGRP

public static final int S_IWGRP
Permissions flag: Permits a file's group to write to the file.

See Also:
Constant Field Values

S_IXGRP

public static final int S_IXGRP
Permissions flag: Permits a file's group to execute the file or to search the file's directory.

See Also:
Constant Field Values

S_IROTH

public static final int S_IROTH
Permissions flag: Permits others to read the file.

See Also:
Constant Field Values

S_IWOTH

public static final int S_IWOTH
Permissions flag: Permits others to write to the file.

See Also:
Constant Field Values

S_IXOTH

public static final int S_IXOTH
Permissions flag: Permits others to execute the file or to search the file's directory.

See Also:
Constant Field Values
Constructor Detail

SftpFileAttributes

public SftpFileAttributes()
Creates a new FileAttributes object.


SftpFileAttributes

public SftpFileAttributes(int version,
                          String charset,
                          com.maverick.util.ByteArrayReader bar)
                   throws IOException
Throws:
IOException
Method Detail

setExtendedAttributes

public void setExtendedAttributes(Map attributes)
Set all the extended attributes. The keys should be of type String, as should the values.

Parameters:
attributes - map of all extended attributes

setExtendedAttribute

public void setExtendedAttribute(String attrName,
                                 String attrValue)
Set a single extended attribute value.

Parameters:
attrName - attribute name
attrValue - attribute value

removeExtendedAttribute

public void removeExtendedAttribute(String attrName)
Set a single extended attribute value.

Parameters:
attrName - attribute name to remove

getExtendedAttributes

public Map getExtendedAttributes()
Get the extended attributes. The key is of type String, as is the value.

Returns:
attribute values

getUID

public String getUID()
Get the UID of the owner.

Returns:
UnsignedInteger32

hasUID

public boolean hasUID()
Get if this file has a username associated with it.

Returns:
has username

hasGID

public boolean hasGID()

setUID

public void setUID(String uid)
Set the UID of the owner.

Parameters:
uid -

setGID

public void setGID(String gid)
Set the GID of this file.

Parameters:
gid -

getGID

public String getGID()
Get the GID of this file.

Returns:
UnsignedInteger32

setSize

public void setSize(com.maverick.util.UnsignedInteger64 size)
Set the size of the file.

Parameters:
size -

getSize

public com.maverick.util.UnsignedInteger64 getSize()
Get the size of the file.

Returns:
UnsignedInteger64

hasSize

public boolean hasSize()

setPermissions

public void setPermissions(com.maverick.util.UnsignedInteger32 permissions)
Set the permissions of the file. This value should be a valid mask of the permissions flags defined within this class.


setPermissionsFromMaskString

public void setPermissionsFromMaskString(String mask)
Set permissions given a UNIX style mask, for example '0644'

Parameters:
mask - mask
Throws:
IllegalArgumentException - if badly formatted string

setPermissionsFromUmaskString

public void setPermissionsFromUmaskString(String umask)
Set the permissions given a UNIX style umask, for example '0022' will result in 0022 ^ 0777.

Parameters:
umask -

setPermissions

public void setPermissions(String newPermissions)
Set the permissions from a string in the format "rwxr-xr-x"

Parameters:
newPermissions -

getPermissions

public com.maverick.util.UnsignedInteger32 getPermissions()
Get the current permissions value.

Returns:
UnsignedInteger32

setTimes

public void setTimes(com.maverick.util.UnsignedInteger64 atime,
                     com.maverick.util.UnsignedInteger64 mtime)
Set the last access and last modified times. These times are represented by integers containing the number of seconds from Jan 1, 1970 UTC. NOTE: You should divide any value returned from Java's System.currentTimeMillis() method by 1000 to set the correct times as this returns the time in milliseconds from Jan 1, 1970 UTC.

Parameters:
atime -
mtime -

getAccessedTime

public com.maverick.util.UnsignedInteger64 getAccessedTime()
Get the last accessed time. This integer value represents the number of seconds from Jan 1, 1970 UTC. When using with Java Date/Time classes you should multiply this value by 1000 as Java uses the time in milliseconds rather than seconds.

Returns:
UnsignedInteger32

hasAccessedTime

public boolean hasAccessedTime()
Get if the file has a last accessed time.

Returns:
UnsignedInteger32
See Also:
getAccessedTime()

getModifiedTime

public com.maverick.util.UnsignedInteger64 getModifiedTime()
Get the last modified time. This integer value represents the number of seconds from Jan 1, 1970 UTC. When using with Java Date/Time classes you should multiply this value by 1000 as Java uses the time in milliseconds rather than seconds.

Returns:
UnsignedInteger32

hasModifiedTime

public boolean hasModifiedTime()
Get if the file has a last modified time.

Returns:
UnsignedInteger32
See Also:
getModifiedTime()

isFlagSet

public boolean isFlagSet(long flag)
Determine if a permissions flag is set.

Parameters:
flag -
Returns:
boolean

toByteArray

public byte[] toByteArray(int version)
                   throws IOException
Returns a formatted byte array suitable for encoding into SFTP subsystem messages.

Returns:
byte[]
Throws:
IOException

getPermissionsString

public String getPermissionsString()
Returns a formatted permissions string.

Returns:
String

getMaskString

public String getMaskString()
Return the UNIX style mode mask

Returns:
mask

isDirectory

public boolean isDirectory()
Determine whether these attributes refer to a directory

Returns:
boolean

isFile

public boolean isFile()
Determine whether these attributes refer to a file.

Returns:
boolean

isLink

public boolean isLink()
Determine whether these attributes refer to a symbolic link.

Returns:
boolean

isFifo

public boolean isFifo()
Determine whether these attributes refer to a pipe.

Returns:
boolean

isBlock

public boolean isBlock()
Determine whether these attributes refer to a block special file.

Returns:
boolean

isCharacter

public boolean isCharacter()
Determine whether these attributes refer to a character device.

Returns:
boolean

isSocket

public boolean isSocket()
Determine whether these attributes refer to a socket.

Returns:
boolean

setType

public void setType(int type)

hasPermissions

public boolean hasPermissions()


Copyright © 2012. All Rights Reserved.