gpt4 book ai didi

ruby - 使用 Ruby FTPS 进行加密传输

转载 作者:数据小太阳 更新时间:2023-10-29 07:36:17 24 4
gpt4 key购买 nike

我正在尝试使用 FTPS 从服务器获取文件。我能够进行身份验证,但是当我尝试列出/获取文件时,我收到“521 数据连接必须加密”。 Net::FTP 模块是否能够做到这一点,我将如何实现它?

我将 Net::FTPTLS 修改为我自己的类,因为我需要存储一个自签名证书。

require 'socket'
require 'openssl'
require 'net/ftp'

module MP
class FTPS < Net::FTP
def connect(host, port=FTP_PORT)
@hostname = host
super
end

def login(user = "anonymous", passwd = nil, cert_file = nil, acct = nil)
store = OpenSSL::X509::Store.new
if cert_file == nil
store.set_default_paths
else
certraw = File.read(cert_file)
cert = OpenSSL::X509::Certificate.new(certraw)
store.add_cert(cert)
end
ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
ctx.cert_store = store
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
ctx.key = nil
ctx.cert = cert
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

下面是尝试获取文件的片段:

def get_ftpclient(host)
FTPS::new(host)
end

def check_for_files
@ftp = get_ftpclient(@host)
@ftp.passive = true
@ftp.login(@user_name, @password, @cert_file)
@ftp.chdir(@remote_dir)
files = @ftp.nlst
files
end

第一次失败。

编辑:我尝试将 voidcmd("PROT P") 添加到登录函数的末尾,但它只是挂了一会儿,然后我最终得到:

IOError: Unsupported record version Unknown-48.48
___BEGIN BACKTRACE___
org/jruby/ext/openssl/SSLSocket.java:564:in `sysread'
/opt/jruby/lib/ruby/gems/1.8/gems/jruby-openssl-0.7.6.1/lib/1.8/openssl/buffering.rb:36:in `fill_rbuff'
/opt/jruby/lib/ruby/gems/1.8/gems/jruby-openssl-0.7.6.1/lib/1.8/openssl/buffering.rb:159:in `eof?'
/opt/jruby/lib/ruby/gems/1.8/gems/jruby-openssl-0.7.6.1/lib/1.8/openssl/buffering.rb:134:in `readline'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:211:in `getline'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:221:in `getmultiline'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:235:in `getresp'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:251:in `voidresp'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:436:in `retrlines'
/opt/jruby/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:422:in `retrlines'
/opt/jruby/lib/ruby/1.8/net/ftp.rb:612:in `nlst'
... etc

最佳答案

我意识到这是一个老问题,但我在研究 FTPS ruby​​ gems 时偶然发现了它。

没有。 net::FTP 本身不支持 FTPS。

我强烈推荐double-bag-ftps .

Provides a child class of Net::FTP to support implicit and explicit FTPS.

在过去的一年里,0.1.1 版对我每天运行来说效果很好。

关于ruby - 使用 Ruby FTPS 进行加密传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16446442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com