class Net::SFTP::Protocol::V04::Name

  1. lib/net/sftp/protocol/04/name.rb
Parent: V04

Represents a single named item on the remote server. This includes the name, and attributes about the item, and the "longname".

For backwards compatibility with the format and interface of the Name structure from previous protocol versions, this also exposes a longname method, which returns a string that can be used to display this item in a directory listing.

Methods

Public Class

  1. new

Public Instance

  1. attributes
  2. directory?
  3. file?
  4. longname
  5. name
  6. symlink?

Attributes

attributes [R]

Attributes instance describing this item.

name [R]

The name of the item on the remote server.

Public Class methods

new (name, attributes)

Create a new Name object with the given name and attributes.

[show source]
# File lib/net/sftp/protocol/04/name.rb, line 18
def initialize(name, attributes)
  @name, @attributes = name, attributes
end

Public Instance methods

directory? ()

Returns true if the item is a directory.

[show source]
# File lib/net/sftp/protocol/04/name.rb, line 23
def directory?
  attributes.directory?
end
file? ()

Returns true if the item is a regular file.

[show source]
# File lib/net/sftp/protocol/04/name.rb, line 33
def file?
  attributes.file?
end
longname ()

Returns a string representing this file, in a format similar to that used by the unix "ls" utility.

[show source]
# File lib/net/sftp/protocol/04/name.rb, line 39
def longname
  @longname ||= begin
    longname = if directory?
      "d"
    elsif symlink?
      "l"
    else
      "-"
    end

    longname << (attributes.permissions & 0400 != 0 ? "r" : "-")
    longname << (attributes.permissions & 0200 != 0 ? "w" : "-")
    longname << (attributes.permissions & 0100 != 0 ? "x" : "-")
    longname << (attributes.permissions & 0040 != 0 ? "r" : "-")
    longname << (attributes.permissions & 0020 != 0 ? "w" : "-")
    longname << (attributes.permissions & 0010 != 0 ? "x" : "-")
    longname << (attributes.permissions & 0004 != 0 ? "r" : "-")
    longname << (attributes.permissions & 0002 != 0 ? "w" : "-")
    longname << (attributes.permissions & 0001 != 0 ? "x" : "-")

    longname << (" %-8s %-8s %8d " % [attributes.owner, attributes.group, attributes.size])

    longname << Time.at(attributes.mtime).strftime("%b %e %H:%M ")
    longname << name
  end
end