LuaSocket FTP Server Always Shut Down

I had success with LuaSocket using TCP tools, but I had problems with its FTP module. I always get a timeout when trying to get a (small) file. I can download the file just fine using Firefox or ftp in passive mode (on Ubuntu Dapper Linux).

I thought that I might need LuaSocket to use passive FTP, but then I found this to be similar to the default. The file that I am trying to retrieve via FTP can be retrieved using passive FTP through other programs on my machine, but not through active mode. I found some talk about “hacking” passive mode support in LuaSocket, and this discussion implies that later versions have stopped using passive mode, but my version seems to use passive anyway (I use 2.0.1, the latest 2.0.2 and, doesn't seem to have any changes pertaining to my use case). I'm a little confused about how this post may relate to my situation, partly because it is very old, and the LuaSocket source now looks a bit like the code in this discussion).

I threw back my code before this:

local ftp = require "socket.ftp"
ftp.TIMEOUT = 10
print(ftp.get("ftp://ftp.us.dell.com/app/dpart.txt"))

This gives me a timeout. I ran it under straceon Linux (same as ptraceSolaris). Here's an abbreviated decryption:

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
recv(3, "230-Welcome to the Dell FTP site."..., 8192, 0) = 971
send(3, "pasv\r\n", 6, 0)               = 6
recv(3, 0x8089a58, 8192, 0)             = -1 EAGAIN (Resource temporarily unavailable)
select(4, [3], NULL, NULL, {9, 999934}) = 0 (Timeout)

There was another site that I was trying to connect to, but it has a password that I can’t post here, but in this case the results were slightly different ... I got a trace, as shown above, but with select()end, then this:

recv(3, "227 Entering Passive Mode (123,456,789,0,12,34)\r\n", 8192, 0) = 49
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
fcntl64(4, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(4, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("123.456.789.0")}, 16) = -1 EINPROGRESS (Operation now in progress)
select(5, [4], [4], NULL, {9, 999694})  = 0 (Timeout)

Compare this with the trace of my ftp program in passive mode (which works fine, although note that it does not set sockets to non-blocking ones like LuaSocket):

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 6
write(5, "PASV\r\n", 6)                 = 6
read(3, "227 Entering Passive Mode (123,456,789,0,12,34)\r\n", 1024) = 51
connect(6, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("123.456.789.0")}, 16) = 0

, LuaSocket FTP- , . , FTP, ( , LuaSocket , , socket/ftp.lua).

- LunaSocket ? , FTP Dell ( , ls ), , LuaSocket , , , FTP Dell .

+3
3

Hm. , , LuaSocket "pasv" . .


Hm. , . , , LUA_PATH. () , . path/to/your/project/socket/ftp.lua.

:

-    self.try(self.tp:command("user", user or USER))
+    self.try(self.tp:command("USER", user or USER))
-        self.try(self.tp:command("pass", password or PASSWORD))
+        self.try(self.tp:command("PASS", password or PASSWORD))
-    self.try(self.tp:command("pasv"))
+    self.try(self.tp:command("PASV"))
-    self.try(self.tp:command("port", arg))
+    self.try(self.tp:command("PORT", arg))
-    local command = sendt.command or "stor"
+    local command = sendt.command or "STOR"
-    self.try(self.tp:command("cwd", dir))
+    self.try(self.tp:command("CWD", dir))
-    self.try(self.tp:command("type", type))
+    self.try(self.tp:command("TYPE", type))
-    self.try(self.tp:command("quit"))
+    self.try(self.tp:command("QUIT"))

, getfenv, getmetatable .., , . , . (LuaSocket)

, RFC0959 all-caps. (, 7- ASCII.)

+3

, FTP, . . RFC959, 5.3 " .        . ,     :                RETR Retr retr ReTr rETr"

+1

, .

Luasocket RFC 959 ( , . 5.2 RFC959)

, Microsoft FTP . .

- pasv PASV , . Lua, .

( 59 ftp.lua)

+1

Source: https://habr.com/ru/post/1698373/


All Articles