-- ********************************************************************* -- wslsock.lua -- ********************************************************************* -- Détermination de la taille d'un fichier function wsls_fsize (name) fso = io.open(name, "r") s = fso:seek("end") io.close(fso) return s end -- Détermination de l'extension d'un fichier function wsls_fext (name) return string.match(name, "(%.%a+)$") end -- Détermination du fichier function wsls_fname (tail) return string.match(tail, "/?([%a%d%.%-]+)$") end -- GET simple function wsls_get (base, tail) http = require("socket.http") ltn12 = require("ltn12") file = wsls_fname(tail) out = io.open(file, "w") r, c, h = http.request { url = "http://" .. base .. tail, sink = ltn12.sink.file(out) } if c == 200 then print ("Le fichier " .. file .. "(" .. wsls_fsize(file) .. " octets) est transféré !") end end -- PUT simple function wsls_put (base, tail) http = require("socket.http") ltn12 = require("ltn12") file = wsls_fname(tail) r, c, h = http.request { method = "PUT", url = "http://" .. base .. tail, source = ltn12.source.file(io.open(file)), headers = { ["content-length"] = wsls_fsize(file) } } if c == 200 then print ("Le fichier " .. file .. "(" .. wsls_fsize(file) .. " octets) est transféré !") end end