diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-25 05:49:07 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-25 05:49:07 +0000 |
commit | 5c13076f8936ae6face0779f75c7e6f148e4989e (patch) | |
tree | 920ecebadb6f210a4f20d37a0f5597abd3f8d7d4 /src | |
parent | 888496aa821cd09d925046250ea98b1512293fd5 (diff) | |
download | luasocket-5c13076f8936ae6face0779f75c7e6f148e4989e.tar.gz luasocket-5c13076f8936ae6face0779f75c7e6f148e4989e.tar.bz2 luasocket-5c13076f8936ae6face0779f75c7e6f148e4989e.zip |
Have to check retr or stor command result before accepting data connection.
Diffstat (limited to 'src')
-rw-r--r-- | src/ftp.lua | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index 6074623..ee1f9aa 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -98,13 +98,13 @@ function metat.__index:send(sendt) | |||
98 | socket.try(self.pasvt or self.portt, "need port or pasv first") | 98 | socket.try(self.pasvt or self.portt, "need port or pasv first") |
99 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end | 99 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end |
100 | socket.try(self.tp:command(sendt.command, sendt.argument)) | 100 | socket.try(self.tp:command(sendt.command, sendt.argument)) |
101 | local code, reply = socket.try(self.tp:check{"2..", "1.."}) | ||
101 | if self.portt then data = socket.try(port(self.portt)) end | 102 | if self.portt then data = socket.try(port(self.portt)) end |
102 | local step = sendt.step or ltn12.pump.step | 103 | local step = sendt.step or ltn12.pump.step |
103 | local code, reply | ||
104 | local checkstep = function(src, snk) | 104 | local checkstep = function(src, snk) |
105 | local readyt = socket.select(readt, nil, 0) | 105 | local readyt = socket.select(readt, nil, 0) |
106 | if readyt[tp] then | 106 | if readyt[tp] then |
107 | code, reply = self.tp:check{"2..", "1.."} | 107 | code, reply = self.tp:check("2..") |
108 | if not code then | 108 | if not code then |
109 | data:close() | 109 | data:close() |
110 | return nil, reply | 110 | return nil, reply |
@@ -116,7 +116,6 @@ function metat.__index:send(sendt) | |||
116 | end | 116 | end |
117 | local sink = socket.sink("close-when-empty", data) | 117 | local sink = socket.sink("close-when-empty", data) |
118 | socket.try(ltn12.pump.all(sendt.source, sink, checkstep)) | 118 | socket.try(ltn12.pump.all(sendt.source, sink, checkstep)) |
119 | if not code then code = socket.try(self.tp:check{"1..", "2.."}) end | ||
120 | if string.find(code, "1..") then socket.try(self.tp:check("2..")) end | 119 | if string.find(code, "1..") then socket.try(self.tp:check("2..")) end |
121 | return 1 | 120 | return 1 |
122 | end | 121 | end |
@@ -126,6 +125,7 @@ function metat.__index:receive(recvt) | |||
126 | socket.try(self.pasvt or self.portt, "need port or pasv first") | 125 | socket.try(self.pasvt or self.portt, "need port or pasv first") |
127 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end | 126 | if self.pasvt then data = socket.try(pasv(self.pasvt)) end |
128 | socket.try(self.tp:command(recvt.command, recvt.argument)) | 127 | socket.try(self.tp:command(recvt.command, recvt.argument)) |
128 | local code = socket.try(self.tp:check{"1..", "2.."}) | ||
129 | if self.portt then data = socket.try(port(self.portt)) end | 129 | if self.portt then data = socket.try(port(self.portt)) end |
130 | local source = socket.source("until-closed", data) | 130 | local source = socket.source("until-closed", data) |
131 | local step = recvt.step or ltn12.pump.step | 131 | local step = recvt.step or ltn12.pump.step |
@@ -135,7 +135,6 @@ function metat.__index:receive(recvt) | |||
135 | return ret, err | 135 | return ret, err |
136 | end | 136 | end |
137 | socket.try(ltn12.pump.all(source, recvt.sink, checkstep)) | 137 | socket.try(ltn12.pump.all(source, recvt.sink, checkstep)) |
138 | local code = socket.try(self.tp:check{"1..", "2.."}) | ||
139 | if string.find(code, "1..") then socket.try(self.tp:check("2..")) end | 138 | if string.find(code, "1..") then socket.try(self.tp:check("2..")) end |
140 | return 1 | 139 | return 1 |
141 | end | 140 | end |