51 posts
Posted 17 May 2013 - 12:55 PM
Hey everyone, I am currently trying to update my API to incorpararate a Auto-Updater. I want to know: How can I download a file from my own server (not pastebin of GitHub).
My current Code:
local version = 1.0
local ckeckForUpdate = http.get("http://www.example.com/currentVersion.php")
local checkForUpdate = checkForUpdate.readAll()
if not version == checkForUpdate then
--Here comes the download from server
else
--API HERE
end
How could I achieve this?
758 posts
Location
Budapest, Hungary
Posted 17 May 2013 - 01:08 PM
Almost. But closing the HTTP handle is a wise thing and another one is not having multiple variable with the same name.
local httpHandle = http.get("whatever.com")
local netVersion = httpHandle.readAll()
httpHandle.close()
-- process netVersion here
EDIT: If the version you're checking for is a number, you should tonumber netVersion. I prefer storing the version number in a string though.
1214 posts
Location
The Sammich Kingdom
Posted 17 May 2013 - 01:10 PM
You would need a PHP script to list the files inside the directory of the files to download. Then you would need a loop to download each file.
Here is the PHP code for it:
http://php.net/manua...ion.readdir.phpThen this would be some example Lua code to loop through it and download it:
local downloadPath = 'http://site.tld/downloads/v1/'
local files = http.get('http://site.tld/downloads/list.php')
local line = files.readLine()
while line do
local req = http.get(downloadPath..line)
local f = fs.open(line, 'w')
f.write(req.readAll())
red.close()
f.close()
line = files.readLine()
end
files.close()
1583 posts
Location
Germany
Posted 17 May 2013 - 05:46 PM
You would need a PHP script to list the files inside the directory of the files to download. Then you would need a loop to download each file.
Here is the PHP code for it:
http://php.net/manua...ion.readdir.phpThen this would be some example Lua code to loop through it and download it:
local downloadPath = 'http://site.tld/downloads/v1/'
local files = http.get('http://site.tld/downloads/list.php')
local line = files.readLine()
while line do
local req = http.get(downloadPath..line)
local f = fs.open(line, 'w')
f.write(req.readAll())
red.close()
f.close()
line = files.readLine()
end
files.close()
There is little typo inline eight. You have written red instead of req ;)/>
1214 posts
Location
The Sammich Kingdom
Posted 17 May 2013 - 05:55 PM
You would need a PHP script to list the files inside the directory of the files to download. Then you would need a loop to download each file.
Here is the PHP code for it:
http://php.net/manua...ion.readdir.phpThen this would be some example Lua code to loop through it and download it:
local downloadPath = 'http://site.tld/downloads/v1/'
local files = http.get('http://site.tld/downloads/list.php')
local line = files.readLine()
while line do
local req = http.get(downloadPath..line)
local f = fs.open(line, 'w')
f.write(req.readAll())
red.close()
f.close()
line = files.readLine()
end
files.close()
There is little typo inline eight. You have written red instead of req ;)/>
I wrote it without testing :P/> But the concept works :P/> I never intend on people using my example code. I assume they will just use it as a guide for their own code.
3 posts
Location
Sweden
Posted 24 September 2013 - 01:44 PM
You would need a PHP script to list the files inside the directory of the files to download. Then you would need a loop to download each file.
Here is the PHP code for it:
http://php.net/manua...ion.readdir.phpThen this would be some example Lua code to loop through it and download it:
local downloadPath = 'http://site.tld/downloads/v1/'
local files = http.get('http://site.tld/downloads/list.php')
local line = files.readLine()
while line do
local req = http.get(downloadPath..line)
local f = fs.open(line, 'w')
f.write(req.readAll())
red.close()
f.close()
line = files.readLine()
end
files.close()
Hello, First post here! :D/>
question: I tested this out for my server to be able to store a database of useful programs for myself mainly but others on the server as well but i would like it to download other programs that are more "testingstuff" to a different directory, now all the stuff is going to the root so how do i change that, using your code?
I have made two separate scripts that access two different folders on my webserver using two different list scripts with php. so this is the only missing part i dont get, i have checked the fs api for clues but with no luck. I just started programming three days ago i might add, so go easy on me :)/> Thanks in advance!
8543 posts
Posted 24 September 2013 - 02:04 PM
This topic has been dead for quite a while, so you may not get the answer you're looking for. Why don't you go read the sticky posts to find where to post your own question as a new member, and post your whole code and ask for help doing what you're looking to accomplish? You'd probably get better help that way.