Class: DoubleBagFTPS
- Inherits:
-
Net::FTP
- Object
- Net::FTP
- DoubleBagFTPS
- Defined in:
- lib/double_bag_ftps.rb
Constant Summary collapse
- EXPLICIT =
:explicit- IMPLICIT =
:implicit- IMPLICIT_PORT =
990
Instance Attribute Summary collapse
-
#ftps_mode ⇒ Object
The form of FTPS that should be used.
-
#ssl_context ⇒ Object
The OpenSSL::SSL::SSLContext to use for creating all OpenSSL::SSL::SSLSocket objects.
Class Method Summary collapse
- .create_ssl_context(params = {}) ⇒ Object
- .open(host, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {}) ⇒ Object
Instance Method Summary collapse
-
#connect(host, port = ftps_implicit? ? IMPLICIT_PORT : FTP_PORT) ⇒ Object
Establishes the command channel.
- #ftps_explicit? ⇒ Boolean
- #ftps_implicit? ⇒ Boolean
-
#initialize(host = nil, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {}) ⇒ DoubleBagFTPS
constructor
A new instance of DoubleBagFTPS.
- #login(user = 'anonymous', passwd = nil, acct = nil, auth = 'TLS') ⇒ Object
Constructor Details
#initialize(host = nil, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {}) ⇒ DoubleBagFTPS
Returns a new instance of DoubleBagFTPS.
19 20 21 22 23 24 |
# File 'lib/double_bag_ftps.rb', line 19 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_mode ⇒ Object
The form of FTPS that should be used. Either EXPLICIT or IMPLICIT. Defaults to EXPLICIT.
14 15 16 |
# File 'lib/double_bag_ftps.rb', line 14 def ftps_mode @ftps_mode end |
#ssl_context ⇒ Object
The OpenSSL::SSL::SSLContext to use for creating all OpenSSL::SSL::SSLSocket objects.
17 18 19 |
# File 'lib/double_bag_ftps.rb', line 17 def ssl_context @ssl_context end |
Class Method Details
.create_ssl_context(params = {}) ⇒ Object
188 189 190 191 192 193 |
# File 'lib/double_bag_ftps.rb', line 188 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
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/double_bag_ftps.rb', line 26 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.
56 57 58 59 |
# File 'lib/double_bag_ftps.rb', line 56 def connect(host, port = ftps_implicit? ? IMPLICIT_PORT : FTP_PORT) @hostname = host super end |
#ftps_explicit? ⇒ Boolean
132 |
# File 'lib/double_bag_ftps.rb', line 132 def ftps_explicit?; @ftps_mode == EXPLICIT end |
#ftps_implicit? ⇒ Boolean
133 |
# File 'lib/double_bag_ftps.rb', line 133 def ftps_implicit?; @ftps_mode == IMPLICIT end |
#login(user = 'anonymous', passwd = nil, acct = nil, auth = 'TLS') ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/double_bag_ftps.rb', line 61 def login(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 |