added fget/fgetd, a simple file server.
This commit is contained in:
parent
a2a5925399
commit
74ae2b3523
@ -23,6 +23,8 @@ net/nshc.lua
|
||||
net/nshd-auth.lua
|
||||
net/nshc-auth.lua
|
||||
net/pxesrv.lua
|
||||
net/fget.lua
|
||||
net/fgetd.lua
|
||||
applications/shutil.lua
|
||||
applications/skex2.lua
|
||||
applications/luash-login.lua
|
||||
|
@ -2,11 +2,12 @@ base/header.lua
|
||||
library/print.lua
|
||||
library/net.lua
|
||||
library/readline.lua
|
||||
net/nshd.lua
|
||||
library/crc32.lua
|
||||
library/chauth.lua
|
||||
net/nshd.lua
|
||||
net/nshd-auth.lua
|
||||
net/fgetd.lua
|
||||
net/fget.lua
|
||||
applications/luash-login.lua
|
||||
applications/shutil.lua
|
||||
library/fs-min.lua
|
||||
|
15
modules/net/fget.lua
Normal file
15
modules/net/fget.lua
Normal file
@ -0,0 +1,15 @@
|
||||
function fget(addr,path,port)
|
||||
local port,S = port or "fget",""
|
||||
ns(addr,port,path)
|
||||
while true do
|
||||
if ev[1] == "net_msg" and ev[2] == addr and ev[3] == port then
|
||||
if ev[4] == "." then
|
||||
break
|
||||
else
|
||||
S=S..ev[4]
|
||||
end
|
||||
end
|
||||
C.yield()
|
||||
end
|
||||
return S
|
||||
end
|
35
modules/net/fgetd.lua
Normal file
35
modules/net/fgetd.lua
Normal file
@ -0,0 +1,35 @@
|
||||
function fgetd_w(evPP,nid,pth)
|
||||
local c,S = "",false
|
||||
if pth:sub(-1) == "/" then
|
||||
local ft=flist(pth)
|
||||
if ft then
|
||||
for k,v in ipairs(ft) do c=c..v.."\n" end S=true
|
||||
else
|
||||
c="failed to open dir"
|
||||
end
|
||||
else
|
||||
local f=io.open(pth)
|
||||
if f then
|
||||
c=f:read("*a")
|
||||
f:close()
|
||||
S=true
|
||||
else
|
||||
c="failed to open file"
|
||||
end
|
||||
end
|
||||
print(c)
|
||||
for i = 1, c:len(), 2048 do
|
||||
ns(nid,evPP,c:sub(i,i+2047))
|
||||
C.yield()
|
||||
end
|
||||
ns(nid,evPP,".")
|
||||
return S
|
||||
end
|
||||
function fgetd(evPP,preP)
|
||||
while true do
|
||||
if ev[1] == "net_msg" and ev[3] == evPP then -- f,p,m
|
||||
print("[fget] "..TS(ev[4])..": "..tostring(fgetd_w(ev[3],ev[2],preP.."/"..ev[4])))
|
||||
end
|
||||
C.yield()
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user