aboutsummaryrefslogtreecommitdiff
path: root/src/ftp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/ftp.lua')
-rw-r--r--src/ftp.lua12
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")
17local tp = require("socket.tp") 17local tp = require("socket.tp")
18local ltn12 = require("ltn12") 18local ltn12 = require("ltn12")
19module("socket.ftp") 19module("socket.ftp")
20getmetatable(_M).__index = nil
20 21
21----------------------------------------------------------------------------- 22-----------------------------------------------------------------------------
22-- Program constants 23-- Program constants
@@ -35,8 +36,8 @@ PASSWORD = "anonymous@anonymous.org"
35----------------------------------------------------------------------------- 36-----------------------------------------------------------------------------
36local metat = { __index = {} } 37local metat = { __index = {} }
37 38
38function open(server, port) 39function 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
199local function tput(putt) 200local 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)
242local function tget(gett) 243local 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
279end) 280end)
280 281
281--getmetatable(_M).__index = nil