0
從我看到支持FTPS的最新Ruby是1.8。我發現了一些可以連接到FTPS的寶石,但是它們在幾年內沒有更新。最近有沒有人需要這樣做?你用什麼寶石?如何使用Ruby 2.3連接到FTPS?
從我看到支持FTPS的最新Ruby是1.8。我發現了一些可以連接到FTPS的寶石,但是它們在幾年內沒有更新。最近有沒有人需要這樣做?你用什麼寶石?如何使用Ruby 2.3連接到FTPS?
您可以簡單地使用net/ftp
標準庫。
ftp = Net::FTP.new('cdimage.debian.org')
ftp.login
ftp.list
或登錄到FTP保護:
ftp.login('username', 'password')
而對於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