class EM::FTPD::FSD::FileOperations

Implements file system specific operations to be used by the base driver

Public Class Methods

bytes( path ) click to toggle source

File size for the given file @param [String] path Absolute path to file @yield [Fixnum] File size or nil if there were errors or the path is not correct

# File lib/em-ftpd-fsd/file_operations.rb, line 40
def self.bytes( path )
  File.size( path )
end
change_dir( path ) click to toggle source

Change current directory @param [String] path Absolute path to the directory @yield [Boolean] True if the change was correct false in other case

# File lib/em-ftpd-fsd/file_operations.rb, line 47
def self.change_dir( path )
  !!File.directory?( path )
end
delete_dir( path ) click to toggle source

Removes the given directory @param [String] path Absolute path to the directory @yield [Boolean] True if the deletion was correct false in other case

# File lib/em-ftpd-fsd/file_operations.rb, line 54
def self.delete_dir( path )
  !!Dir.delete( path )
end
delete_file( path ) click to toggle source

Removes the given file @param [String] path Absolute path to the file @yield [Boolean] True if the deletion was correct false in other case

# File lib/em-ftpd-fsd/file_operations.rb, line 61
def self.delete_file( path )
  !!File.delete( path )
end
dir_contents( path ) click to toggle source

Gives information about the directory content @param [String] path Absolute path to the directory @yield [Array] List of DirectoryItem-ish containing information about

directory. Nil if there were errors or the path is not correct.
# File lib/em-ftpd-fsd/file_operations.rb, line 27
def self.dir_contents( path )
  Dir.entries( path ).map do |filename|
    EM::FTPD::FSD::DirectoryItem.new(
      name:      filename,
      size:      File.size?( "#{path}/#{filename}" ),
      directory: File.directory?( "#{path}/#{filename}" )
    )
  end
end
get_file( path ) click to toggle source

Send a file to the client @param [String] path Absolute path to the file @yield [String] File content or nil if the file does not exist or an error ocurred

# File lib/em-ftpd-fsd/file_operations.rb, line 83
def self.get_file( path )
  File.read( path )
end
make_dir( path ) click to toggle source

Creates a new directory @param [String] path Absolute path to the new directory @yield [Boolean] True if the new directory was created false in other case

# File lib/em-ftpd-fsd/file_operations.rb, line 76
def self.make_dir( path )
  !!Dir.mkdir( path )
end
put_file( path, tmp_path ) click to toggle source

Upload a new file to FTP server @param [String] path Absolute path to final location of the file @param [String] tmp_path Absolute path to temporary file created by server @yield [Fixnum] New uploaded file size or false if there were an error

# File lib/em-ftpd-fsd/file_operations.rb, line 91
def self.put_file( path, tmp_path )
  FileUtils.copy( tmp_path, path )
  File.size( tmp_path )
end
rename( from_path, to_path ) click to toggle source

Moves the given file to a new location @param [String] from_path Absolute path to existing file @param [String] to_path Absolute path to new file @yield [Boolean] True if file was moved without errors, false otherwise

# File lib/em-ftpd-fsd/file_operations.rb, line 69
def self.rename( from_path, to_path )
  !!File.rename( from_path, to_path )
end