Module: EM::FTPD::Authentication

Included in:
Server
Defined in:
lib/em-ftpd/authentication.rb

Instance Method Summary collapse

Instance Method Details

#cmd_pass(param) ⇒ Object

handle the PASS FTP command. This is the second stage of a user logging in



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/em-ftpd/authentication.rb', line 25

def cmd_pass(param)
  send_response "202 User already logged in" and return unless @user.nil?
  send_param_required and return if param.nil?
  send_response "530 password with no username" and return if @requested_user.nil?

  # return an error message if:
  #  - the specified username isn't in our system
  #  - the password is wrong

  @driver.authenticate(@requested_user, param) do |result|
    if result
      @name_prefix = "/"
      @user = @requested_user
      @requested_user = nil
      send_response "230 OK, password correct"
    else
      @user = nil
      send_response "530 incorrect login. not logged in."
    end
  end
end

#cmd_user(param) ⇒ Object

handle the USER FTP command. This is a user attempting to login. we simply store the requested user name as an instance variable and wait for the password to be submitted before doing anything



17
18
19
20
21
22
# File 'lib/em-ftpd/authentication.rb', line 17

def cmd_user(param)
  send_param_required and return if param.nil?
  send_response("500 Already logged in") and return unless @user.nil?
  @requested_user = param
  send_response "331 OK, password required"
end

#initializeObject



4
5
6
7
8
# File 'lib/em-ftpd/authentication.rb', line 4

def initialize
  @user = nil
  @requested_user = nil
  super
end

#logged_in?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/em-ftpd/authentication.rb', line 10

def logged_in?
  @user.nil? ? false : true
end