Why does this work:
docname = 'dir/file.gz’
Net::HTTP::Proxy(proxy_addr, proxy_port).start(site) { |http|
response = http.get(base + docname)
File.open(File.join(File.dirname(FILE), docname), “wb+”) { |f|
f.write(response.body) }
}
But this doesn’t:
docs = File.readlines( File.join(File.dirname(FILE),
“doclist.txt”) )
Net::HTTP::Proxy(proxy_addr, proxy_port).start(site) { |http|
docs.each { |docname|
response = http.get(base + docname)
File.open(File.join(File.dirname(FILE), docname), “wb+”) { |f|
f.write(response.body) }
}
}
Fails with:
c:/MyTools/getdocs.rb:16:in initialize': Invalid argument - c:/MyTools/dir/file.gz (Errno::EINVAL) from c:/MyTools/getdocs.rb:16:in
open’
from c:/MyTools/getdocs.rb:16
from c:/MyTools/getdocs.rb:13:in start' from c:/langs/ruby/lib/ruby/1.8/net/http.rb:324:in
start’
from c:/MyTools/getdocs.rb:13
from c:/MyTools/getdocs.rb:12:in `each’
from c:/MyTools/getdocs.rb:12
All the subdirectories exist. It obviously can get and write the file
(as the first example shows). The only difference is the 'docs.each’
loop. The docs variable is initialized propererly with the list of files
(I’ve checked).
Anyone?
Cheers,
Assaph