Class: EM::FTPD::FSD::FileOperations
- Inherits:
-
Object
- Object
- EM::FTPD::FSD::FileOperations
- 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
-
.bytes(path) {|Fixnum| ... } ⇒ Object
File size for the given file.
-
.change_dir(path) {|Boolean| ... } ⇒ Object
Change current directory.
-
.delete_dir(path) {|Boolean| ... } ⇒ Object
Removes the given directory.
-
.delete_file(path) {|Boolean| ... } ⇒ Object
Removes the given file.
-
.dir_contents(path) {|Array| ... } ⇒ Object
Gives information about the directory content.
-
.get_file(path) {|String| ... } ⇒ Object
Send a file to the client.
-
.make_dir(path) {|Boolean| ... } ⇒ Object
Creates a new directory.
-
.put_file(path, tmp_path) {|Fixnum| ... } ⇒ Object
Upload a new file to FTP server.
-
.rename(from_path, to_path) {|Boolean| ... } ⇒ Object
Moves the given file to a new location.
Class Method Details
.bytes(path) {|Fixnum| ... } ⇒ Object
File size for the given file
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
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
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
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
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
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
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
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
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 |