Class: Ftpd::Protocols

Inherits:
Object
  • Object
show all
Includes:
Codes
Defined in:
lib/ftpd/protocols.rb

Overview

With the commands EPORT and EPSV, the client sends a protocol code to indicate whether it wants an IPV4 or an IPV6 connection. This class contains functions related to that protocol code.

Defined Under Namespace

Modules: Codes

Constant Summary

Constants included from Codes

Codes::IPV4, Codes::IPV6

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Protocols

Returns a new instance of Protocols.

Parameters:

  • socket (TCPSocket, OpenSSL::SSL::SSLSocket)

    The socket. It doesn't matter whether it's the server socket (the one on which #accept is called), or the socket returned by #accept.


19
20
21
# File 'lib/ftpd/protocols.rb', line 19

def initialize(socket)
  @socket = socket
end

Instance Method Details

#protocol_codesArray<Integer>

What protocol codes does the socket support?

Returns:

  • (Array<Integer>)

    List of protocol codes


35
36
37
38
39
40
# File 'lib/ftpd/protocols.rb', line 35

def protocol_codes
  [
    (IPV4 if supports_ipv4?),
    (IPV6 if supports_ipv6?),
  ].compact
end

#supports_protocol?(protocol_code) ⇒ Boolean

Can the socket support a connection in the indicated protocol?

Parameters:

  • protocol_code (Integer)

    protocol code

Returns:

  • (Boolean)

27
28
29
# File 'lib/ftpd/protocols.rb', line 27

def supports_protocol?(protocol_code)
  protocol_codes.include?(protocol_code)
end