# File lib/rudy/cli/aws/ec2/candy.rb, line 116
116:     def copy
117:       
118:       opts = {}
119:       opts[:group] = @option.group if @option.group
120:       opts[:group] = :any if @option.all
121: 
122:       opts[:id] = @argv.shift if Rudy::Utils.is_id?(:instance, @argv.first)
123:       opts[:id] &&= [opts[:id]].flatten
124:       
125:       # Options to be sent to Net::SSH
126:       rye_opts = { :user => @global.user || Rudy.sysinfo.user, :debug => nil  }
127:       if @@global.pkey 
128:         raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
129:         raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
130:         rye_opts[:keys] = @@global.pkey 
131:       end
132:       
133:       opts[:paths] = @argv
134:       opts[:dest] = opts[:paths].pop
135:     
136:       opts[:task] = :download if %w(dl download).member?(@alias) || @option.download
137:       opts[:task] = :upload if %w(ul upload).member?(@alias)
138:       opts[:task] ||= :upload
139:       opts[:user] = @global.user || Rudy.sysinfo.user
140:     
141:     
142:       # Options to be sent to Rye::Box
143:       info = @@global.quiet ? nil : STDERR
144:       rye_opts = { :user => @global.user || Rudy.sysinfo.user, :info => info }
145:       if @@global.pkey 
146:         raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
147:         raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
148:         rye_opts[:keys] = @@global.pkey 
149:       end
150:       
151: 
152:       checked = false
153:       lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running, opts[:id]) do |inst|
154:         
155:         if @option.print
156:           scp_command inst.dns_public, @@global.pkey, opts[:user], opts[:paths], opts[:dest], (opts[:task] == :download), false, @option.print
157:           next
158:         end
159:         
160:         # Print header
161:         if @@global.quiet
162:           print "You are #{rye_opts[:user].bright}. " if !checked # only the 1st
163:         else
164:           print "Connecting #{rye_opts[:user].bright}@#{inst.dns_public} "
165:           li "(#{inst.awsid}, groups: #{inst.groups.join(', ')})"
166:         end
167:         
168:         # Make sure we want to run this command on all instances
169:         if !checked
170:           #execute_check(:medium) if opts[:user] == "root"
171:           checked = true
172:         end
173:         
174:         # Open the connection and run the command
175:         rbox = Rye::Box.new(inst.dns_public, rye_opts)
176:         rbox.send(opts[:task], opts[:paths], opts[:dest])
177:       end
178: 
179:     end