Class: DoubleBagFTPS

Inherits:
Net::FTP
  • Object
show all
Defined in:
lib/double_bag_ftps.rb

Constant Summary collapse

EXPLICIT =
:explicit
IMPLICIT =
:implicit
IMPLICIT_PORT =
990

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {}) ⇒ DoubleBagFTPS

Returns a new instance of DoubleBagFTPS.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/double_bag_ftps.rb', line 20

def initialize(host = nil, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {})
  raise ArgumentError unless valid_ftps_mode?(ftps_mode)
  @ftps_mode = ftps_mode
  @ssl_context = DoubleBagFTPS.create_ssl_context(ssl_context_params)
  super(host, user, passwd, acct)
end

Instance Attribute Details

#ftps_modeObject

The form of FTPS that should be used. Either EXPLICIT or IMPLICIT. Defaults to EXPLICIT.



15
16
17
# File 'lib/double_bag_ftps.rb', line 15

def ftps_mode
  @ftps_mode
end

#ssl_contextObject

The OpenSSL::SSL::SSLContext to use for creating all OpenSSL::SSL::SSLSocket objects.



18
19
20
# File 'lib/double_bag_ftps.rb', line 18

def ssl_context
  @ssl_context
end

Class Method Details

.create_ssl_context(params = {}) ⇒ Object



203
204
205
206
207
208
# File 'lib/double_bag_ftps.rb', line 203

def DoubleBagFTPS.create_ssl_context(params = {})
  raise 'SSL extension not installed' unless defined?(OpenSSL)
  context = OpenSSL::SSL::SSLContext.new
  context.set_params(params)
  return context
end

.open(host, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/double_bag_ftps.rb', line 27

def DoubleBagFTPS.open(host, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {})
  if block_given?
    ftps = new(host, user, passwd, acct, ftps_mode, ssl_context_params)
    begin
      yield ftps
    ensure
      ftps.close
    end
  else
    new(host, user, passwd, acct, ftps_mode, ssl_context_params)
  end
end

Instance Method Details

#connect(host, port = ftps_implicit? ? IMPLICIT_PORT : FTP_PORT) ⇒ Object

Establishes the command channel. Override parent to record host name for verification, and allow default implicit port.



57
58
59
60
# File 'lib/double_bag_ftps.rb', line 57

def connect(host, port = ftps_implicit? ? IMPLICIT_PORT : FTP_PORT)
  @hostname = host
  super
end

#ftps_explicit?Boolean

Returns:

  • (Boolean)


147
# File 'lib/double_bag_ftps.rb', line 147

def ftps_explicit?; @ftps_mode == EXPLICIT end

#ftps_implicit?Boolean

Returns:

  • (Boolean)


148
# File 'lib/double_bag_ftps.rb', line 148

def ftps_implicit?; @ftps_mode == IMPLICIT end

#login(user = 'anonymous', passwd = nil, acct = nil, auth = 'TLS') ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/double_bag_ftps.rb', line 62

def (user = 'anonymous', passwd = nil, acct = nil, auth = 'TLS')
  if ftps_explicit?
    synchronize do
      sendcmd('AUTH ' + auth) # Set the security mechanism
      @sock = ssl_socket(@sock)
    end
  end
  
  super(user, passwd, acct)
  voidcmd('PBSZ 0') # The expected value for Protection Buffer Size (PBSZ) is 0 for TLS/SSL 
  voidcmd('PROT P') # Set data channel protection level to Private
end