Module: EM::FTPD::Directories
- Included in:
- Server
- Defined in:
- lib/em-ftpd/directories.rb
Instance Method Summary collapse
-
#cmd_cdup(param) ⇒ Object
(also: #cmd_xcup)
go up a directory, really just an alias.
-
#cmd_cwd(param) ⇒ Object
(also: #cmd_xcwd)
change directory.
-
#cmd_list(param) ⇒ Object
return a detailed list of files and directories.
-
#cmd_mkd(param) ⇒ Object
make directory.
-
#cmd_nlst(param) ⇒ Object
return a listing of the current directory, one per line, each line separated by the standard FTP EOL sequence.
-
#cmd_pwd(param) ⇒ Object
(also: #cmd_xpwd)
return the current directory.
-
#cmd_rmd(param) ⇒ Object
(also: #cmd_xrmd)
delete a directory.
- #default_files(dir) ⇒ Object
Instance Method Details
#cmd_cdup(param) ⇒ Object Also known as: cmd_xcup
go up a directory, really just an alias
4 5 6 7 |
# File 'lib/em-ftpd/directories.rb', line 4 def cmd_cdup(param) and return unless logged_in? cmd_cwd("..") end |
#cmd_cwd(param) ⇒ Object Also known as: cmd_xcwd
change directory
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/em-ftpd/directories.rb', line 14 def cmd_cwd(param) and return unless logged_in? path = build_path(param) @driver.change_dir(path) do |result| if result @name_prefix = path send_response "250 Directory changed to #{path}" else end end end |
#cmd_list(param) ⇒ Object
return a detailed list of files and directories
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/em-ftpd/directories.rb', line 67 def cmd_list(param) and return unless logged_in? send_response "150 Opening ASCII mode data connection for file list" param = '' if param.to_s == '-a' @driver.dir_contents(build_path(param)) do |files| now = Time.now lines = files.map { |item| sizestr = (item.size || 0).to_s.rjust(12) "#{item.directory ? 'd' : '-'}#{item. || 'rwxrwxrwx'} 1 #{item.owner || 'owner'} #{item.group || 'group'} #{sizestr} #{(item.time || now).strftime("%b %d %H:%M")} #{item.name}" } send_outofband_data(lines) end end |
#cmd_mkd(param) ⇒ Object
make directory
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/em-ftpd/directories.rb', line 32 def cmd_mkd(param) and return unless logged_in? send_param_required and return if param.nil? @driver.make_dir(build_path(param)) do |result| if result send_response "257 Directory created" else send_action_not_taken end end end |
#cmd_nlst(param) ⇒ Object
return a listing of the current directory, one per line, each line separated by the standard FTP EOL sequence. The listing is returned to the client over a data socket.
49 50 51 52 53 54 55 56 |
# File 'lib/em-ftpd/directories.rb', line 49 def cmd_nlst(param) and return unless logged_in? send_response "150 Opening ASCII mode data connection for file list" @driver.dir_contents(build_path(param)) do |files| send_outofband_data(files.map(&:name)) end end |
#cmd_pwd(param) ⇒ Object Also known as: cmd_xpwd
return the current directory
84 85 86 87 |
# File 'lib/em-ftpd/directories.rb', line 84 def cmd_pwd(param) and return unless logged_in? send_response "257 \"#{@name_prefix}\" is the current directory" end |
#cmd_rmd(param) ⇒ Object Also known as: cmd_xrmd
delete a directory
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/em-ftpd/directories.rb', line 93 def cmd_rmd(param) and return unless logged_in? send_param_required and return if param.nil? @driver.delete_dir(build_path(param)) do |result| if result send_response "250 Directory deleted." else send_action_not_taken end end end |
#default_files(dir) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/em-ftpd/directories.rb', line 59 def default_files(dir) [ DirectoryItem.new(:name => '.', :permissions => 'rwxrwxrwx', :directory => true), DirectoryItem.new(:name => '..', :permissions => 'rwxrwxrwx', :directory => true), ] end |