class Rtprov::Sftp
Attributes
host[R]
password[R]
user[R]
Public Class Methods
new(host, user, password)
click to toggle source
# File lib/rtprov/sftp.rb, line 8 def initialize(host, user, password) @host = host.dup.freeze @user = user.dup.freeze @password = password.dup.freeze end
Public Instance Methods
get(src)
click to toggle source
# File lib/rtprov/sftp.rb, line 14 def get(src) Dir.mktmpdir do |dir| dest = File.join(dir, File.basename(src)) run "get #{src} -o #{dest}" File.read(dest) end end
put(src, dest)
click to toggle source
# File lib/rtprov/sftp.rb, line 22 def put(src, dest) run "put #{src} -o #{dest}" end
Private Instance Methods
run(command)
click to toggle source
# File lib/rtprov/sftp.rb, line 27 def run(command) # use lftp (instead of sftp) to specify user and password by arguments o, e, s = Open3.capture3("lftp", "-u", "#{user},#{password}", "sftp://#{host}", stdin_data: command) unless s.success? raise "lftp command `#{command}` failed on sftp://#{host} by #{user}: #{e}" end o end