2018-08-11 13:59:44 +10:00
|
|
|
local net = require "minitel"
|
2018-02-19 21:04:22 +11:00
|
|
|
local event = require "event"
|
2018-07-27 03:38:45 +10:00
|
|
|
local shell = require "shell"
|
2018-02-19 21:04:22 +11:00
|
|
|
|
2018-06-22 12:58:45 +10:00
|
|
|
local function parseURL(url)
|
2018-06-22 11:48:21 +10:00
|
|
|
local proto,addr = url:match("(.-)://(.+)")
|
|
|
|
addr = addr or url
|
|
|
|
local hp, path = addr:match("(.-)(/.*)")
|
|
|
|
hp, path = hp or addr, path or "/"
|
2018-04-18 10:22:59 +10:00
|
|
|
local host, port = hp:match("(.+):(.+)")
|
2018-06-22 11:48:21 +10:00
|
|
|
host = host or hp
|
|
|
|
return proto, host, port, path
|
2018-04-18 10:22:59 +10:00
|
|
|
end
|
2018-02-19 21:04:22 +11:00
|
|
|
|
2018-07-27 03:38:45 +10:00
|
|
|
local tArgs, tFlags = shell.parse(...)
|
2018-06-22 11:48:21 +10:00
|
|
|
local proto, host, port, path = parseURL(tArgs[1])
|
2018-06-22 12:58:45 +10:00
|
|
|
port = tonumber(port) or 70
|
2018-02-19 21:04:22 +11:00
|
|
|
|
2018-02-19 21:23:19 +11:00
|
|
|
local socket = net.open(host,port)
|
2018-07-27 03:38:45 +10:00
|
|
|
if tFlags.s then
|
|
|
|
socket:write("s"..path.."\n")
|
|
|
|
else
|
|
|
|
socket:write("t"..path.."\n")
|
|
|
|
end
|
2018-02-19 22:49:23 +11:00
|
|
|
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
|
2018-02-19 21:04:22 +11:00
|
|
|
repeat
|
2018-02-19 21:23:19 +11:00
|
|
|
l = socket:read(1024)
|
2018-02-19 21:04:22 +11:00
|
|
|
io.write(l)
|
|
|
|
os.sleep(0.5)
|
2018-02-19 21:23:19 +11:00
|
|
|
until socket.state == "closed" and l == ""
|