lib/double_bag_ftps.rb in double-bag-ftps-0.1.0 vs lib/double_bag_ftps.rb in double-bag-ftps-0.1.1

- old
+ new

@@ -119,14 +119,13 @@ # skip 2XX for some ftp servers resp = getresp if resp[0] == ?2 if resp[0] != ?1 raise FTPReplyError, resp end - - temp_ssl_sock = ssl_socket(sock) - conn = temp_ssl_sock.accept - temp_ssl_sock.close + conn = sock.accept + conn = ssl_socket(conn) + sock.close end return conn end private :transfercmd @@ -148,17 +147,45 @@ sock.connect print "get: #{sock.peer_cert.to_text}" if @debug_mode unless @ssl_context.verify_mode == OpenSSL::SSL::VERIFY_NONE sock.post_connection_check(@hostname) end + decorate_socket sock return sock end private :ssl_socket + # Ruby 2.0's Ftp class closes sockets by first doing a shutdown, + # setting the read timeout, and doing a read. OpenSSL doesn't + # have those methods, so fake it. + # + # Ftp calls #close in an ensure block, so the socket will still get + # closed. + + def decorate_socket(sock) + + def sock.shutdown(how) + @shutdown = true + end + + def sock.read_timeout=(seconds) + end + + # Skip read after shutdown. Prevents 2.0 from hanging in + # Ftp#close + + def sock.read(*args) + return if @shutdown + super(*args) + end + + end + private :decorate_socket + 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 - + end