Class Net::SFTP::Operations::Dir
In: lib/net/sftp/operations/dir.rb
Parent: Object

A convenience class for working with remote directories. It provides methods for searching and enumerating directory entries, similarly to the standard ::Dir class.

  sftp.dir.foreach("/remote/path") do |entry|
    puts entry.name
  end

  p sftp.dir.entries("/remote/path").map { |e| e.name }

  sftp.dir.glob("/remote/path", "**/*.rb") do |entry|
    puts entry.name
  end

Methods

[]   entries   foreach   glob   new  

Attributes

sftp  [R]  The SFTP session object that drives this directory factory.

Public Class methods

Create a new instance on top of the given SFTP session instance.

Public Instance methods

Identical to calling glob with a flags parameter of 0 and no block. Simply returns the matched entries as an array.

Returns an array of Name objects representing the items in the given remote directory, path.

Calls the block once for each entry in the named directory on the remote server. Yields a Name object to the block, rather than merely the name of the entry.

Works as ::Dir.glob, matching (possibly recursively) all directory entries under path against pattern. If a block is given, matches will be yielded to the block as they are found; otherwise, they will be returned in an array when the method finishes.

Because working over an SFTP connection is always going to be slower than working purely locally, don‘t expect this method to perform with the same level of alacrity that ::Dir.glob does; it will work best for shallow directory hierarchies with relatively few directories, though it should be able to handle modest numbers of files in each directory.

[Validate]