Class: EM::FTPD::Server

Inherits:
Connection
  • Object
show all
Includes:
Authentication, Directories, Files, Protocols::LineProtocol
Defined in:
lib/em-ftpd/server.rb

Constant Summary collapse

LBRK =
"\r\n"
COMMANDS =
%w[quit type user retr stor port cdup cwd dele rmd pwd list size
syst mkd pass xcup xpwd xcwd xrmd rest allo nlst pasv help
noop mode rnfr rnto stru]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Files

#cmd_dele, #cmd_rest, #cmd_retr, #cmd_rnfr, #cmd_rnto, #cmd_size, #cmd_stor, #cmd_stor_streamed, #cmd_stor_tempfile

Methods included from Directories

#cmd_cdup, #cmd_cwd, #cmd_list, #cmd_mkd, #cmd_nlst, #cmd_pwd, #cmd_rmd, #default_files

Methods included from Authentication

#cmd_pass, #cmd_user, #logged_in?

Constructor Details

#initialize(driver, *args) ⇒ Server

Returns a new instance of Server.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/em-ftpd/server.rb', line 24

def initialize(driver, *args)
  if driver.is_a?(Class) && args.empty?
    @driver = driver.new
  elsif driver.is_a?(Class)
    @driver = driver.new *args
  else
    @driver = driver
  end
  @datasocket = nil
  @listen_sig = nil
  super()
end

Instance Attribute Details

#datasocketObject

Returns the value of attribute datasocket.



22
23
24
# File 'lib/em-ftpd/server.rb', line 22

def datasocket
  @datasocket
end

#name_prefixObject (readonly)

Returns the value of attribute name_prefix.



21
22
23
# File 'lib/em-ftpd/server.rb', line 21

def name_prefix
  @name_prefix
end

#rootObject (readonly)

Returns the value of attribute root.



21
22
23
# File 'lib/em-ftpd/server.rb', line 21

def root
  @root
end

Instance Method Details

#post_initObject



37
38
39
40
41
42
# File 'lib/em-ftpd/server.rb', line 37

def post_init
  @mode   = :binary
  @name_prefix = "/"

  send_response "220 FTP server (em-ftpd) ready"
end

#receive_line(str) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/em-ftpd/server.rb', line 44

def receive_line(str)
  cmd, param = parse_request(str)

  # if the command is contained in the whitelist, and there is a method
  # to handle it, call it. Otherwise send an appropriate response to the
  # client
  if COMMANDS.include?(cmd) && self.respond_to?("cmd_#{cmd}".to_sym, true)
    begin
      self.__send__("cmd_#{cmd}".to_sym, param)
    rescue Exception => err
      puts "#{err.class}: #{err}"
      puts err.backtrace.join("\n")
    end
  else
    send_response "500 Sorry, I don't understand #{cmd.upcase}"
  end
end