1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-09-20 02:08:48 +10:00
OC-Minitel/FRequest/OpenOS/usr/bin/fget.lua
2018-04-15 18:28:41 +10:00

31 lines
627 B
Lua

local net = require "net"
local event = require "event"
local tArgs = {...}
local address, path = tArgs[1], tArgs[2]
local port = 70
local host,nport = address:match("(.+):(%d+)")
port = nport or port
host = host or address
local socket = net.open(host,port)
socket:write("t"..path.."\n")
local c = socket:read(1)
repeat
c = socket:read(1)
os.sleep(0.5)
until c ~= ""
if c == "n" then
print(path..": Not found.")
elseif c == "f" then
print("Failure: ")
elseif c == "d" then
print("Directory listing for "..path)
end
repeat
l = socket:read(1024)
io.write(l)
os.sleep(0.5)
until socket.state == "closed" and l == ""