Module: Ftpd::DiskFileSystem::List

Includes:
TranslateExceptions
Included in:
Ftpd::DiskFileSystem, ReadOnlyDiskFileSystem
Defined in:
lib/ftpd/disk_file_system.rb

Overview

DiskFileSystem mixin providing directory listing

Instance Method Summary collapse

Methods included from TranslateExceptions

included, #translate_exception

Instance Method Details

#dir(ftp_path) ⇒ Array<String>

Expand a path that may contain globs into a list of paths of matching files and directories. The paths returned are fully qualified, relative to the root of the virtual file system.

For example, suppose these files exist on the physical file system:

/var/lib/ftp/foo/foo
/var/lib/ftp/foo/subdir/bar
/var/lib/ftp/foo/subdir/baz

and that the directory /var/lib/ftp is the root of the virtual file system. Then:

dir('foo')         # => ['/foo']
dir('subdir')      # => ['/subdir']
dir('subdir/*')    # => ['/subdir/bar', '/subdir/baz']
dir('*')           # => ['/foo', '/subdir']

Called for:

  • LIST

  • NLST

If missing, then these commands are not supported.

Parameters:

  • ftp_path (String)

    The virtual path

Returns:

  • (Array<String>)


311
312
313
314
315
# File 'lib/ftpd/disk_file_system.rb', line 311

def dir(ftp_path)
  Dir[expand_ftp_path(ftp_path)].map do |path|
    path.sub(/^#{@data_dir}/, '')
  end
end

#file_info(ftp_path) ⇒ FileInfo

Get information about a single file or directory. Should follow symlinks (per http://cr.yp.to/ftp/list/eplf.html, “lstat() is not a good idea for FTP directory listings”).

Called for:

  • LIST

If missing, then these commands are not supported.

Parameters:

  • ftp_path (String)

    The virtual path

Returns:



268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/ftpd/disk_file_system.rb', line 268

def file_info(ftp_path)
  stat = File.stat(expand_ftp_path(ftp_path))
  FileInfo.new(:ftype => stat.ftype,
               :group => gid_name(stat.gid),
               :identifier => identifier(stat),
               :mode => stat.mode,
               :mtime => stat.mtime,
               :nlink => stat.nlink,
               :owner => uid_name(stat.uid),
               :path => ftp_path,
               :size => stat.size)
end