-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwget
47 lines (35 loc) · 741 Bytes
/
wget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local function printUsage()
print( "Usages:" )
print( "wget <url>" )
end
local tArgs = { ... }
if #tArgs < 1 then
printUsage()
return
end
if not http then
print( "requires http API" )
print( "Set enableAPI_http to true in ComputerCraft.cfg" )
return
end
local url = tArgs[1]
local sFile = "file"
local sPath = shell.resolve( sFile )
if fs.exists( sPath ) then
print( "File already exists" )
return
end
-- GET the contents
write( "Downloading... " )
local response = http.get(url)
if response then
print( "Success." )
local sResponse = response.readAll()
response.close()
local file = fs.open( sPath, "w" )
file.write( sResponse )
file.close()
print( "Downloaded as "..sFile )
else
print( "Failed." )
end