据我所知,支持 FTPS 的最新 Ruby 是 1.8。我发现了一些可以连接到 FTPS 的 gem,但是它们已经好几年没有更新了。最近有人必须这样做吗?你用的是什么宝石?
问问题
1013 次
2 回答
0
对于 FTPS,您可以使用 net/sftp https://github.com/net-ssh/net-sftp
代码示例:
require 'net/sftp'
Net::SFTP.start('host', 'username', :password => 'password') do |sftp|
# upload a file or directory to the remote host
sftp.upload!("/path/to/local", "/path/to/remote")
# download a file or directory from the remote host
sftp.download!("/path/to/remote", "/path/to/local")
# grab data off the remote host directly to a buffer
data = sftp.download!("/path/to/remote")
# open and write to a pseudo-IO for a remote file
sftp.file.open("/path/to/remote", "w") do |f|
f.puts "Hello, world!\n"
end
# open and read from a pseudo-IO for a remote file
sftp.file.open("/path/to/remote", "r") do |f|
puts f.gets
end
# create a directory
sftp.mkdir! "/path/to/directory"
# list the entries in a directory
sftp.dir.foreach("/path/to/directory") do |entry|
puts entry.longname
end
end
于 2016-03-11T23:14:20.020 回答
0
您可以简单地使用net/ftp
标准库。
ftp = Net::FTP.new('cdimage.debian.org')
ftp.login
ftp.list
或登录受保护的 ftp:
ftp.login('username', 'password')
于 2016-03-11T21:37:56.397 回答