Module: EBPS::Preprocess::Copy

Defined in:
lib/ebps/preprocess/copy.rb

Class Method Summary collapse

Class Method Details

.preprocess(data = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ebps/preprocess/copy.rb', line 7

def self.preprocess data={}
  report = ["The following files were copied"]
  data['transfers'].each do |path, destination|
    FileUtils.mkdir_p File.dirname(destination)
    uri = ::URI.parse path
    case uri.scheme
    when 'ftp'
      Net::FTP.open uri.host do |ftp|
        ftp. uri.user, uri.password
        ftp.chdir File.dirname(uri.path)
        ftp.getbinaryfile File.basename(uri.path), destination
      end
    else
      FileUtils.cp path, destination
    end
    report.push sprintf(" - from %s to %s")
  end
  report.join "\n"
end