Module: EasyDownloader::Sftp

Included in:
AbstractLoader
Defined in:
lib/easy_downloader/sftp.rb

Instance Method Summary collapse

Instance Method Details

#sftp_download(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/easy_downloader/sftp.rb', line 3

def sftp_download(options)
  Net::SFTP.start(options.host,
                  options.user,
                  sftp_password_option(options.password)) do |sftp|

    files = sftp.dir.glob(options.remote_path, options.remote_pattern)
    options.result.found(files.size, files.map(&:name))

    files.map(&:name).each do |path|
      options.result.starting_path(path)
      options.load_count += 1 if sftp.download!("#{options.remote_path}#{path}", "#{options.local_path}#{path}")
      options.result.finished_path(path)
      options.result.files_loaded << "#{options.local_path}#{path}"
    end
  end
end

#sftp_password_option(password) ⇒ Object



20
21
22
23
24
# File 'lib/easy_downloader/sftp.rb', line 20

def sftp_password_option(password)
  password ?
    {:password => password} :
    Hash.new
end