I\'m new with lua but working on an application that works on specific files with given path. Now, I want to work on files that I download. Is there any lua libraries or lin
You can use the LuaSocket library and its http.request function to download using HTTP from an URL.
The function has two flavors:
http.request('http://stackoverflow.com')
http.request { url = 'http://stackoverflow.com', ... }
The simple call returns 4 values - the entire content of the URL in a string, HTTP response code, headers and response line. You can then save the content to a file using the io library.
The advanced call allows you to set several parameters like HTTP method and headers. An important parameter is sink
. It represents a LTN12-style sink. For storing to file, you can use sink.file:
local file = ltn12.sink.file(io.open('stackoverflow', 'w'))
http.request {
url = 'http://stackoverflow.com',
sink = file,
}