Class: EM::FTPD::FSD::FileOperations

Inherits:
Object
  • Object
show all
Defined in:
lib/em-ftpd-fsd/file_operations.rb

Overview

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

Class Method Summary collapse

Class Method Details

.bytes(path) {|Fixnum| ... } ⇒ Object

File size for the given file

Parameters:

  • path (String)

    Absolute path to file

Yields:

  • (Fixnum)

    File size or nil if there were errors or the path is not correct



40
41
42
# File 'lib/em-ftpd-fsd/file_operations.rb', line 40

def self.bytes( path )
  File.size( path )
end

.change_dir(path) {|Boolean| ... } ⇒ Object

Change current directory

Parameters:

  • path (String)

    Absolute path to the directory

Yields:

  • (Boolean)

    True if the change was correct false in other case



47
48
49
# File 'lib/em-ftpd-fsd/file_operations.rb', line 47

def self.change_dir( path )
  !!File.directory?( path )
end

.delete_dir(path) {|Boolean| ... } ⇒ Object

Removes the given directory

Parameters:

  • path (String)

    Absolute path to the directory

Yields:

  • (Boolean)

    True if the deletion was correct false in other case



54
55
56
# File 'lib/em-ftpd-fsd/file_operations.rb', line 54

def self.delete_dir( path )
  !!Dir.delete( path )
end

.delete_file(path) {|Boolean| ... } ⇒ Object

Removes the given file

Parameters:

  • path (String)

    Absolute path to the file

Yields:

  • (Boolean)

    True if the deletion was correct false in other case



61
62
63
# File 'lib/em-ftpd-fsd/file_operations.rb', line 61

def self.delete_file( path )
  !!File.delete( path )
end

.dir_contents(path) {|Array| ... } ⇒ Object

Gives information about the directory content

Parameters:

  • path (String)

    Absolute path to the directory

Yields:

  • (Array)

    List of DirectoryItem-ish containing information about directory. Nil if there were errors or the path is not correct.



27
28
29
30
31
32
33
34
35
# 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) {|String| ... } ⇒ Object

Send a file to the client

Parameters:

  • path (String)

    Absolute path to the file

Yields:

  • (String)

    File content or nil if the file does not exist or an error ocurred



83
84
85
# File 'lib/em-ftpd-fsd/file_operations.rb', line 83

def self.get_file( path )
  File.read( path )
end

.make_dir(path) {|Boolean| ... } ⇒ Object

Creates a new directory

Parameters:

  • path (String)

    Absolute path to the new directory

Yields:

  • (Boolean)

    True if the new directory was created false in other case



76
77
78
# File 'lib/em-ftpd-fsd/file_operations.rb', line 76

def self.make_dir( path )
  !!Dir.mkdir( path )
end

.put_file(path, tmp_path) {|Fixnum| ... } ⇒ Object

Upload a new file to FTP server

Parameters:

  • path (String)

    Absolute path to final location of the file

  • tmp_path (String)

    Absolute path to temporary file created by server

Yields:

  • (Fixnum)

    New uploaded file size or false if there were an error



91
92
93
94
# 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) {|Boolean| ... } ⇒ Object

Moves the given file to a new location

Parameters:

  • from_path (String)

    Absolute path to existing file

  • to_path (String)

    Absolute path to new file

Yields:

  • (Boolean)

    True if file was moved without errors, false otherwise



69
70
71
# File 'lib/em-ftpd-fsd/file_operations.rb', line 69

def self.rename( from_path, to_path )
  !!File.rename( from_path, to_path )
end