Class: Ftpd::DataServerFactory::SpecificPortRange

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpd/data_server_factory/specific_port_range.rb

Overview

Factory for creating TCPServer used for passive mode connections. This factory binds to a random port within a specific range of ports.

Instance Method Summary collapse

Constructor Details

#initialize(interface, ports) ⇒ SpecificPortRange

Returns a new instance of SpecificPortRange.

Parameters:

  • interface (String)

    The IP address of the interface to bind to (e.g. “127.0.0.1”)

  • ports (nil, Range)

    The range of ports to bind to.



15
16
17
18
# File 'lib/ftpd/data_server_factory/specific_port_range.rb', line 15

def initialize(interface, ports)
  @interface = interface
  @ports = ports
end

Instance Method Details

#make_tcp_serverTCPServer

Returns:

  • (TCPServer)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ftpd/data_server_factory/specific_port_range.rb', line 21

def make_tcp_server
  ports_to_try = @ports.to_a.shuffle
  until ports_to_try.empty?
    port = ports_to_try.shift
    begin
      return TCPServer.new(@interface, port)
    rescue Errno::EADDRINUSE
    end
  end
  TCPServer.new(@interface, 0)
end