Class | Net::SFTP::Protocol::V04::Name |
In: |
lib/net/sftp/protocol/04/name.rb
|
Parent: | Object |
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.
attributes | [R] | Attributes instance describing this item. |
name | [R] | The name of the item on the remote server. |
Returns true if the item is a directory.
# File lib/net/sftp/protocol/04/name.rb, line 23 23: def directory? 24: attributes.directory? 25: end
Returns true if the item is a regular file.
# File lib/net/sftp/protocol/04/name.rb, line 33 33: def file? 34: attributes.file? 35: end
Returns a string representing this file, in a format similar to that used by the unix "ls" utility.
# File lib/net/sftp/protocol/04/name.rb, line 39 39: def longname 40: @longname ||= begin 41: longname = if directory? 42: "d" 43: elsif symlink? 44: "l" 45: else 46: "-" 47: end 48: 49: longname << (attributes.permissions & 0400 != 0 ? "r" : "-") 50: longname << (attributes.permissions & 0200 != 0 ? "w" : "-") 51: longname << (attributes.permissions & 0100 != 0 ? "x" : "-") 52: longname << (attributes.permissions & 0040 != 0 ? "r" : "-") 53: longname << (attributes.permissions & 0020 != 0 ? "w" : "-") 54: longname << (attributes.permissions & 0010 != 0 ? "x" : "-") 55: longname << (attributes.permissions & 0004 != 0 ? "r" : "-") 56: longname << (attributes.permissions & 0002 != 0 ? "w" : "-") 57: longname << (attributes.permissions & 0001 != 0 ? "x" : "-") 58: 59: longname << (" %-8s %-8s %8d " % [attributes.owner, attributes.group, attributes.size]) 60: 61: longname << Time.at(attributes.mtime).strftime("%b %e %H:%M ") 62: longname << name 63: end 64: end