diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-04 15:15:45 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-04 15:15:45 +0000 |
| commit | 9ed7f955e5fc69af9bf1794fa2c8cd227981ba24 (patch) | |
| tree | 8c3521366ef84f534bbec278437be7ea24e2ac1c /src/ftp.lua | |
| parent | 63d60223da9de60f873ca08a25dbd9512c998929 (diff) | |
| download | luasocket-9ed7f955e5fc69af9bf1794fa2c8cd227981ba24.tar.gz luasocket-9ed7f955e5fc69af9bf1794fa2c8cd227981ba24.tar.bz2 luasocket-9ed7f955e5fc69af9bf1794fa2c8cd227981ba24.zip | |
Só pra não perder se der merda.
Diffstat (limited to 'src/ftp.lua')
| -rw-r--r-- | src/ftp.lua | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index 842fdbb..79772f8 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
| @@ -5,21 +5,22 @@ | |||
| 5 | -- Conforming to: RFC 959, LTN7 | 5 | -- Conforming to: RFC 959, LTN7 |
| 6 | -- RCS ID: $Id$ | 6 | -- RCS ID: $Id$ |
| 7 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
| 8 | -- make sure LuaSocket is loaded | 8 | |
| 9 | require("socket") | 9 | ----------------------------------------------------------------------------- |
| 10 | -- get LuaSocket namespace | 10 | -- Load other required modules |
| 11 | local socket = _G[LUASOCKET_LIBNAME] | 11 | ----------------------------------------------------------------------------- |
| 12 | 12 | local socket = require("socket") | |
| 13 | -- require other modules | 13 | local ltn12 = require("ltn12") |
| 14 | require("ltn12") | 14 | local url = require("url") |
| 15 | require("url") | 15 | local tp = require("tp") |
| 16 | require("tp") | 16 | |
| 17 | 17 | ----------------------------------------------------------------------------- | |
| 18 | -- create namespace inside LuaSocket namespace | 18 | -- Setup namespace |
| 19 | socket.ftp = socket.ftp or {} | 19 | ----------------------------------------------------------------------------- |
| 20 | local ftp = {} | ||
| 20 | -- make all module globals fall into namespace | 21 | -- make all module globals fall into namespace |
| 21 | setmetatable(socket.ftp, { __index = _G }) | 22 | setmetatable(ftp, { __index = _G }) |
| 22 | setfenv(1, socket.ftp) | 23 | setfenv(1, ftp) |
| 23 | 24 | ||
| 24 | ----------------------------------------------------------------------------- | 25 | ----------------------------------------------------------------------------- |
| 25 | -- Program constants | 26 | -- Program constants |
| @@ -196,8 +197,8 @@ local default = { | |||
| 196 | scheme = "ftp" | 197 | scheme = "ftp" |
| 197 | } | 198 | } |
| 198 | 199 | ||
| 199 | local function parse(url) | 200 | local function parse(u) |
| 200 | local putt = socket.try(socket.url.parse(url, default)) | 201 | local putt = socket.try(url.parse(u, default)) |
| 201 | socket.try(putt.scheme == "ftp", "invalid scheme '" .. putt.scheme .. "'") | 202 | socket.try(putt.scheme == "ftp", "invalid scheme '" .. putt.scheme .. "'") |
| 202 | socket.try(putt.host, "invalid host") | 203 | socket.try(putt.host, "invalid host") |
| 203 | local pat = "^type=(.)$" | 204 | local pat = "^type=(.)$" |
| @@ -208,8 +209,8 @@ local function parse(url) | |||
| 208 | return putt | 209 | return putt |
| 209 | end | 210 | end |
| 210 | 211 | ||
| 211 | local function sput(url, body) | 212 | local function sput(u, body) |
| 212 | local putt = parse(url) | 213 | local putt = parse(u) |
| 213 | putt.source = ltn12.source.string(body) | 214 | putt.source = ltn12.source.string(body) |
| 214 | return tput(putt) | 215 | return tput(putt) |
| 215 | end | 216 | end |
| @@ -230,8 +231,8 @@ local function tget(gett) | |||
| 230 | return ftp:close() | 231 | return ftp:close() |
| 231 | end | 232 | end |
| 232 | 233 | ||
| 233 | local function sget(url, body) | 234 | local function sget(u, body) |
| 234 | local gett = parse(url) | 235 | local gett = parse(u) |
| 235 | local t = {} | 236 | local t = {} |
| 236 | gett.sink = ltn12.sink.table(t) | 237 | gett.sink = ltn12.sink.table(t) |
| 237 | tget(gett) | 238 | tget(gett) |
