diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
| commit | d55a5826e81136a9ecf65c4cd407152a56684dc2 (patch) | |
| tree | 109ad44c75cee890ad5e98583e12b15b5e65a18e /src/ftp.lua | |
| parent | a2b780bf7a78c66d54a248fa99b5fc862c12a127 (diff) | |
| download | luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.gz luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.bz2 luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.zip | |
Few tweaks in installation, some missing files, etc.
Diffstat (limited to 'src/ftp.lua')
| -rw-r--r-- | src/ftp.lua | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index c83c1cb..5e1b685 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
| @@ -40,7 +40,7 @@ function open(server, port, create) | |||
| 40 | local f = base.setmetatable({ tp = tp }, metat) | 40 | local f = base.setmetatable({ tp = tp }, metat) |
| 41 | -- make sure everything gets closed in an exception | 41 | -- make sure everything gets closed in an exception |
| 42 | f.try = socket.newtry(function() f:close() end) | 42 | f.try = socket.newtry(function() f:close() end) |
| 43 | return f | 43 | return f |
| 44 | end | 44 | end |
| 45 | 45 | ||
| 46 | function metat.__index:portconnect() | 46 | function metat.__index:portconnect() |
| @@ -71,20 +71,20 @@ function metat.__index:pasv() | |||
| 71 | local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" | 71 | local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" |
| 72 | local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) | 72 | local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) |
| 73 | self.try(a and b and c and d and p1 and p2, reply) | 73 | self.try(a and b and c and d and p1 and p2, reply) |
| 74 | self.pasvt = { | 74 | self.pasvt = { |
| 75 | ip = string.format("%d.%d.%d.%d", a, b, c, d), | 75 | ip = string.format("%d.%d.%d.%d", a, b, c, d), |
| 76 | port = p1*256 + p2 | 76 | port = p1*256 + p2 |
| 77 | } | 77 | } |
| 78 | if self.server then | 78 | if self.server then |
| 79 | self.server:close() | 79 | self.server:close() |
| 80 | self.server = nil | 80 | self.server = nil |
| 81 | end | 81 | end |
| 82 | return self.pasvt.ip, self.pasvt.port | 82 | return self.pasvt.ip, self.pasvt.port |
| 83 | end | 83 | end |
| 84 | 84 | ||
| 85 | function metat.__index:port(ip, port) | 85 | function metat.__index:port(ip, port) |
| 86 | self.pasvt = nil | 86 | self.pasvt = nil |
| 87 | if not ip then | 87 | if not ip then |
| 88 | ip, port = self.try(self.tp:getcontrol():getsockname()) | 88 | ip, port = self.try(self.tp:getcontrol():getsockname()) |
| 89 | self.server = self.try(socket.bind(ip, 0)) | 89 | self.server = self.try(socket.bind(ip, 0)) |
| 90 | ip, port = self.try(self.server:getsockname()) | 90 | ip, port = self.try(self.server:getsockname()) |
| @@ -100,11 +100,11 @@ end | |||
| 100 | 100 | ||
| 101 | function metat.__index:send(sendt) | 101 | function metat.__index:send(sendt) |
| 102 | self.try(self.pasvt or self.server, "need port or pasv first") | 102 | self.try(self.pasvt or self.server, "need port or pasv first") |
| 103 | -- if there is a pasvt table, we already sent a PASV command | 103 | -- if there is a pasvt table, we already sent a PASV command |
| 104 | -- we just get the data connection into self.data | 104 | -- we just get the data connection into self.data |
| 105 | if self.pasvt then self:pasvconnect() end | 105 | if self.pasvt then self:pasvconnect() end |
| 106 | -- get the transfer argument and command | 106 | -- get the transfer argument and command |
| 107 | local argument = sendt.argument or | 107 | local argument = sendt.argument or |
| 108 | url.unescape(string.gsub(sendt.path or "", "^[/\\]", "")) | 108 | url.unescape(string.gsub(sendt.path or "", "^[/\\]", "")) |
| 109 | if argument == "" then argument = nil end | 109 | if argument == "" then argument = nil end |
| 110 | local command = sendt.command or "stor" | 110 | local command = sendt.command or "stor" |
| @@ -137,7 +137,7 @@ end | |||
| 137 | function metat.__index:receive(recvt) | 137 | function metat.__index:receive(recvt) |
| 138 | self.try(self.pasvt or self.server, "need port or pasv first") | 138 | self.try(self.pasvt or self.server, "need port or pasv first") |
| 139 | if self.pasvt then self:pasvconnect() end | 139 | if self.pasvt then self:pasvconnect() end |
| 140 | local argument = recvt.argument or | 140 | local argument = recvt.argument or |
| 141 | url.unescape(string.gsub(recvt.path or "", "^[/\\]", "")) | 141 | url.unescape(string.gsub(recvt.path or "", "^[/\\]", "")) |
| 142 | if argument == "" then argument = nil end | 142 | if argument == "" then argument = nil end |
| 143 | local command = recvt.command or "retr" | 143 | local command = recvt.command or "retr" |
| @@ -220,7 +220,7 @@ local function parse(u) | |||
| 220 | socket.try(t.scheme == "ftp", "wrong scheme '" .. t.scheme .. "'") | 220 | socket.try(t.scheme == "ftp", "wrong scheme '" .. t.scheme .. "'") |
| 221 | socket.try(t.host, "missing hostname") | 221 | socket.try(t.host, "missing hostname") |
| 222 | local pat = "^type=(.)$" | 222 | local pat = "^type=(.)$" |
| 223 | if t.params then | 223 | if t.params then |
| 224 | t.type = socket.skip(2, string.find(t.params, pat)) | 224 | t.type = socket.skip(2, string.find(t.params, pat)) |
| 225 | socket.try(t.type == "a" or t.type == "i", | 225 | socket.try(t.type == "a" or t.type == "i", |
| 226 | "invalid type '" .. t.type .. "'") | 226 | "invalid type '" .. t.type .. "'") |
| @@ -229,7 +229,7 @@ local function parse(u) | |||
| 229 | end | 229 | end |
| 230 | 230 | ||
| 231 | local function sput(u, body) | 231 | local function sput(u, body) |
| 232 | local putt = parse(u) | 232 | local putt = parse(u) |
| 233 | putt.source = ltn12.source.string(body) | 233 | putt.source = ltn12.source.string(body) |
| 234 | return tput(putt) | 234 | return tput(putt) |
| 235 | end | 235 | end |
| @@ -253,7 +253,7 @@ local function tget(gett) | |||
| 253 | end | 253 | end |
| 254 | 254 | ||
| 255 | local function sget(u) | 255 | local function sget(u) |
| 256 | local gett = parse(u) | 256 | local gett = parse(u) |
| 257 | local t = {} | 257 | local t = {} |
| 258 | gett.sink = ltn12.sink.table(t) | 258 | gett.sink = ltn12.sink.table(t) |
| 259 | tget(gett) | 259 | tget(gett) |
