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.



21
22
23
# File 'lib/ftpd/protocols.rb', line 21

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



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

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)


29
30
31
# File 'lib/ftpd/protocols.rb', line 29

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