functiondl.protos.fget(host,optPort,path,dest)-- string string string number -- boolean -- Downloads path from host (on optPort or 70), printing the directory listing, or saving the file to dest.
localsocket=assert(net.open(host,optPortor70))
socket:write(string.format("t%s\n",path))
localstatus
repeat
coroutine.yield()
status=socket:read(1)
untilstatus~=""
ifstatus=="d"then
io.write("Directory Listing:\n")
localtmp=""
repeat
coroutine.yield()
tmp=socket:read("*a")
io.write(tmp)
untilsocket.state=="closed"andtmp==""
returntrue
elseifstatus=="y"then
ifnotdestthen
error("Must provide local path to save remote files.")
end
io.write(string.format("Saving %s to %s...\n",path,dest))
localf=assert(io.open(dest,"wb"))
localtmp=""
repeat
coroutine.yield()
tmp=socket:read("*a")
f:write(tmp)
untilsocket.state=="closed"andtmp==""
f:close()
print("Done.")
returntrue
else
localerr,tmp="",""
repeat
coroutine.yield()
tmp=socket:read("*a")
err=err..tmp
untilsocket.state=="closed"andtmp==""
error(string.format("Got error from remote host: %s",err))
end
end
functiondl.protos.http(host,optPort,path,dest,url)-- string string string number -- boolean -- Downloads *url* to *dest* via the internet card, if available.