diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-08-12 05:56:32 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-08-12 05:56:32 +0000 |
| commit | 0c3cdd5ef2485a79d6fec9261f2850c41577d5b3 (patch) | |
| tree | d69164c9f815e2d0308ba3f0d15b18e67163d879 /src/ftp.lua | |
| parent | 37f7af4b9f1250e3c3439df03d43cf291a4d6f37 (diff) | |
| download | luasocket-0c3cdd5ef2485a79d6fec9261f2850c41577d5b3.tar.gz luasocket-0c3cdd5ef2485a79d6fec9261f2850c41577d5b3.tar.bz2 luasocket-0c3cdd5ef2485a79d6fec9261f2850c41577d5b3.zip | |
Final push for release...
Diffstat (limited to 'src/ftp.lua')
| -rw-r--r-- | src/ftp.lua | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index 841df5f..226e04c 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
| @@ -17,6 +17,7 @@ local url = require("socket.url") | |||
| 17 | local tp = require("socket.tp") | 17 | local tp = require("socket.tp") |
| 18 | local ltn12 = require("ltn12") | 18 | local ltn12 = require("ltn12") |
| 19 | module("socket.ftp") | 19 | module("socket.ftp") |
| 20 | getmetatable(_M).__index = nil | ||
| 20 | 21 | ||
| 21 | ----------------------------------------------------------------------------- | 22 | ----------------------------------------------------------------------------- |
| 22 | -- Program constants | 23 | -- Program constants |
| @@ -35,8 +36,8 @@ PASSWORD = "anonymous@anonymous.org" | |||
| 35 | ----------------------------------------------------------------------------- | 36 | ----------------------------------------------------------------------------- |
| 36 | local metat = { __index = {} } | 37 | local metat = { __index = {} } |
| 37 | 38 | ||
| 38 | function open(server, port) | 39 | function open(server, port, create) |
| 39 | local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT)) | 40 | local tp = socket.try(tp.connect(server, port or PORT, create, TIMEOUT)) |
| 40 | local f = base.setmetatable({ tp = tp }, metat) | 41 | local f = base.setmetatable({ tp = tp }, metat) |
| 41 | -- make sure everything gets closed in an exception | 42 | -- make sure everything gets closed in an exception |
| 42 | f.try = socket.newtry(function() f:close() end) | 43 | f.try = socket.newtry(function() f:close() end) |
| @@ -199,7 +200,7 @@ end | |||
| 199 | local function tput(putt) | 200 | local function tput(putt) |
| 200 | putt = override(putt) | 201 | putt = override(putt) |
| 201 | socket.try(putt.host, "missing hostname") | 202 | socket.try(putt.host, "missing hostname") |
| 202 | local f = open(putt.host, putt.port) | 203 | local f = open(putt.host, putt.port, putt.create) |
| 203 | f:greet() | 204 | f:greet() |
| 204 | f:login(putt.user, putt.password) | 205 | f:login(putt.user, putt.password) |
| 205 | if putt.type then f:type(putt.type) end | 206 | if putt.type then f:type(putt.type) end |
| @@ -242,7 +243,7 @@ end) | |||
| 242 | local function tget(gett) | 243 | local function tget(gett) |
| 243 | gett = override(gett) | 244 | gett = override(gett) |
| 244 | socket.try(gett.host, "missing hostname") | 245 | socket.try(gett.host, "missing hostname") |
| 245 | local f = open(gett.host, gett.port) | 246 | local f = open(gett.host, gett.port, gett.create) |
| 246 | f:greet() | 247 | f:greet() |
| 247 | f:login(gett.user, gett.password) | 248 | f:login(gett.user, gett.password) |
| 248 | if gett.type then f:type(gett.type) end | 249 | if gett.type then f:type(gett.type) end |
| @@ -264,7 +265,7 @@ command = socket.protect(function(cmdt) | |||
| 264 | cmdt = override(cmdt) | 265 | cmdt = override(cmdt) |
| 265 | socket.try(cmdt.host, "missing hostname") | 266 | socket.try(cmdt.host, "missing hostname") |
| 266 | socket.try(cmdt.command, "missing command") | 267 | socket.try(cmdt.command, "missing command") |
| 267 | local f = open(cmdt.host, cmdt.port) | 268 | local f = open(cmdt.host, cmdt.port, cmdt.create) |
| 268 | f:greet() | 269 | f:greet() |
| 269 | f:login(cmdt.user, cmdt.password) | 270 | f:login(cmdt.user, cmdt.password) |
| 270 | f.try(f.tp:command(cmdt.command, cmdt.argument)) | 271 | f.try(f.tp:command(cmdt.command, cmdt.argument)) |
| @@ -278,4 +279,3 @@ get = socket.protect(function(gett) | |||
| 278 | else return tget(gett) end | 279 | else return tget(gett) end |
| 279 | end) | 280 | end) |
| 280 | 281 | ||
| 281 | --getmetatable(_M).__index = nil | ||
