class Chef::Knife::S3Download
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/s3_download.rb, line 38 def run $stdout.sync = true validate! if config[:bucket].nil? puts "No bucket specified" exit 1 end if config[:pathname].nil? puts "No path specified" exit 1 end if config[:localfile].nil? config[:localfile] = config[:pathname] #TODO: should strip "directory" elements from the path? end if File.exists?(config[:localfile]) and config[:overwrite].nil? print config[:localfile] + " exists. Overwrite (y/n)? " ans=$stdin.gets if !ans.match(/^y/i) puts "Not overwriting, exiting" exit 0 end end begin remote_file = connection.directories.get(config[:bucket]).files.get(config[:pathname]) local_file = File.open(config[:localfile],'w') local_file.write(remote_file.body) end end