I Recently Got a Strange problem, quite a strange requirement from one of the clients.They needed to build a query whose result will be an XML. We need to get that XML on the local system over HTTP without any login credentials.
The Biggest catch was, apart from the files themselves, we even had to fetch the metadata along with the documents.
Here is a Ruby Script that helped us:
require 'net/http'
Net::HTTP.start("www.safewlabs.com") { |http|
resp = http.get("/images/SAFEW.jpg")
open("safewlogo.jpg", "wb") { |file|
file.write(resp.body)
}
}
puts "File Copied"
Description: The Script above uses the net/http library of Ruby. Ruby Net HTTP API resides here. We first access the URL of the server where the Particular file is hosted.Then in the variable put the response of the getmethod of the http protocol.In this case it uses the absolute path of the file.Once done, Ruby file I/O method open is used, where we open a new file on our local system and write the fetched information into it (file.write(resp.body)).
The Copied file is stored in the same folder as the script.You can also set a target folder for it.