Method: Net::FTP#connect
- Defined in:
- lib/net/ftp.rb
#connect(host, port = FTP_PORT) ⇒ Object
Establishes an FTP connection to host, optionally overriding the default port. If the environment variable SOCKS_SERVER is set, sets up the connection through a SOCKS proxy. Raises an exception (typically Errno::ECONNREFUSED) if the connection cannot be established.
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/net/ftp.rb', line 402 def connect(host, port = FTP_PORT) debug_print "connect: #{host}:#{port}" synchronize do @host = host @bare_sock = open_socket(host, port) if @ssl_context begin unless @implicit_ftps set_socket(BufferedSocket.new(@bare_sock, read_timeout: @read_timeout)) voidcmd("AUTH TLS") end set_socket(BufferedSSLSocket.new(start_tls_session(@bare_sock), read_timeout: @read_timeout), @implicit_ftps) if @private_data_connection voidcmd("PBSZ 0") voidcmd("PROT P") end rescue OpenSSL::SSL::SSLError, OpenTimeout @sock.close raise end else set_socket(BufferedSocket.new(@bare_sock, read_timeout: @read_timeout)) end end end |