我从中获取文件的供应商正在从 FTP 更改为通过 SSL 的 FTP。
我正在尝试将我的代码更新net/ftp
为net/ftptls
我需要连接的新主机没有经过认证,我的脚本报告了这个错误。
主机名与服务器证书不匹配
供应商不会解决这个问题。
看着/usr/lib/ruby/1.8/net/ftptls.rb
我认为猴子修补 FTPTLS 以忽略不受信任的主机不会太难。
我尝试更改verify_mode
并OpenSSL::SSL::VERIFY_NONE
注释掉 post_connection_check` 行。
都没有工作。
关于如何做到这一点的任何想法?
require 'socket'
require 'openssl'
require 'net/ftp'
module Net
class FTPTLS < FTP
def connect(host, port=FTP_PORT)
@hostname = host
super
end
def login(user = "anonymous", passwd = nil, acct = nil)
store = OpenSSL::X509::Store.new
store.set_default_paths
ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
ctx.cert_store = store
ctx.verify_mode = 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)
super(user, passwd, acct)
voidcmd("PBSZ 0")
end
end
end