Class: Net::SFTP::Protocol::V01::Attributes

Class | Net::SFTP::Protocol::V01::Attributes
In: | lib/net/sftp/protocol/01/attributes.rb
Parent: | Object

A class representing the attributes of a file or directory on the server. It may be used to specify new attributes, or to query existing attributes.

To specify new attributes, just pass a hash as the argument to the constructor. The following keys are supported:

- :size:: the size of the file
- :uid:: the user-id that owns the file (integer)
- :gid:: the group-id that owns the file (integer)
- :owner:: the name of the user that owns the file (string)
- :group:: the name of the group that owns the file (string)
- :permissions:: the permissions on the file (integer, e.g. 0755)
- :atime:: the access time of the file (integer, seconds since epoch)
- :mtime:: the modification time of the file (integer, seconds since epoch)
- :extended:: a hash of name/value pairs identifying extended info

Likewise, when the server sends an Attributes object, all of the above attributes are exposed as methods (though not all will be set with non-nil values from the server).

### Methods

directory? file? from_buffer gid group new owner symbolic_type symlink? to_s type uid

### Constants

F_SIZE | = | 0x00000001
F_UIDGID | = | 0x00000002
F_PERMISSIONS | = | 0x00000004
F_ACMODTIME | = | 0x00000008
F_EXTENDED | = | 0x80000000
T_REGULAR | = | 1
T_DIRECTORY | = | 2
T_SYMLINK | = | 3
T_SPECIAL | = | 4
T_UNKNOWN | = | 5
T_SOCKET | = | 6
T_CHAR_DEVICE | = | 7
T_BLOCK_DEVICE | = | 8
T_FIFO | = | 9

### Attributes

atime | [RW] | The last access time of the file
attributes | [R] | The hash of name/value pairs that backs this Attributes instance
extended | [RW] | The hash of name/value pairs identifying extended information about the file
gid | [W] | The group-id of the user that owns the file
mtime | [RW] | The modification time of the file
permissions | [RW] | The permissions on the file
size | [RW] | The size of the file.
uid | [W] | The user-id of the user that owns the file

### Public Class methods

from_buffer(buffer)

Parses the given buffer and returns an Attributes object compsed from the data extracted from it.

new(attributes={})

Create a new Attributes instance with the given attributes. The following keys are supported:

- :size:: the size of the file
- :uid:: the user-id that owns the file (integer)
- :gid:: the group-id that owns the file (integer)
- :owner:: the name of the user that owns the file (string)
- :group:: the name of the group that owns the file (string)
- :permissions:: the permissions on the file (integer, e.g. 0755)
- :atime:: the access time of the file (integer, seconds since epoch)
- :mtime:: the modification time of the file (integer, seconds since epoch)
- :extended:: a hash of name/value pairs identifying extended info

### Public Instance methods

directory?()

Returns true if these attributes appear to describe a directory.

file?()

Returns true if these attributes appear to describe a regular file.

gid()

Returns the group-id of the group that owns the file, or `nil` if that information is not available. If a :group key exists, but not a :gid key, the Etc module will be used to reverse lookup the id from the name. This might fail on some systems (e.g., Windows).

group()

Returns the group name of the group that owns the file, or `nil` if that information is not available. If the :gid is given, but not the :group, the Etc module will be used to lookup the name from the id. This might fail on some systems (e.g. Windows).

owner()

Returns the username of the user that owns the file, or `nil` if that information is not available. If the :uid is given, but not the :owner, the Etc module will be used to lookup the name from the id. This might fail on some systems (e.g. Windows).

symbolic_type()

Returns the type as a symbol, rather than an integer, for easier use in Ruby programs.

symlink?()

Returns true if these attributes appear to describe a symlink.

to_s()

Convert the object to a string suitable for passing in an SFTP packet. This is the raw representation of the attribute packet payload, and is not intended to be human readable.

type()

Inspects the permissions bits to determine what type of entity this attributes object represents. If will return one of the T_ constants.

uid()

Returns the user-id of the user that owns the file, or `nil` if that information is not available. If an :owner key exists, but not a :uid key, the Etc module will be used to reverse lookup the id from the name. This might fail on some systems (e.g., Windows).

[Validate]