Sha256: cffe497bb7ae43e1e8701eb28ec41c4c190025838c647fa30ac2f1b87903ff39
Contents?: true
Size: 852 Bytes
Versions: 4
Compression:
Stored size: 852 Bytes
Contents
require "open3" require "tmpdir" module Rtprov class Sftp attr_reader :host, :user, :password def initialize(host, user, password) @host = host.dup.freeze @user = user.dup.freeze @password = password.dup.freeze end def get(src) Dir.mktmpdir do |dir| dest = File.join(dir, File.basename(src)) run "get #{src} -o #{dest}" File.read(dest) end end def put(src, dest) run "put #{src} -o #{dest}" end private 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rtprov-0.1.3 | lib/rtprov/sftp.rb |
rtprov-0.1.2 | lib/rtprov/sftp.rb |
rtprov-0.1.1 | lib/rtprov/sftp.rb |
rtprov-0.1.0 | lib/rtprov/sftp.rb |