我所做的,而不是monkeypatching ruby 本身,是将它的副本带入我的项目的/lib 中。
module Net
class FTPTLS < FTP
def connect(host, port=FTP_PORT)
@hostname = host
super
end
def login(user = "anonymous", params = {:password => nil, :acct => nil, :ignore_cert => false})
store = OpenSSL::X509::Store.new
store.set_default_paths
ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
ctx.cert_store = store
ctx.verify_mode = params[:ignore_cert] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
ctx.key = nil
ctx.cert = nil
voidcmd("AUTH TLS")
@sock = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
@sock.connect
@sock.post_connection_check(@hostname) unless params[:ignore_cert]
super(user, params[:password], params[:acct])
voidcmd("PBSZ 0")
end
end
end
我还清理了传递的参数。你会这样使用它:
require 'ftptls' # Use my local version, not net/ftptls
@ftp_connection = Net::FTPTLS.new()
@ftp_connection.passive = true
@ftp_connection.connect(host, 21)
@ftp_connection.login('user', :password => 'pass', :ignore_cert => true)
高温高压