luasocket icon indicating copy to clipboard operation
luasocket copied to clipboard

socket.ftp and "553 User not allow" without extra '/' for some servers

Open codeninja-ru opened this issue 6 months ago • 4 comments

I have an issue while trying to connect to ftp on WD My Cloud (it uses some modification of pure-ftp server)

this code returns:

local ftp = require("socket.ftp")

f, e = ftp.get("ftp://myserver/books/test.txt;type=i")
print(f)
print(e)
nil
553 User not allow

but curl or wget get the file without fail

curl "ftp://myserver/books/test.txt"
Hello World!

I starts to work when I add an extra '/' after the host

local ftp = require("socket.ftp")

f, e = ftp.get("ftp://myserver//books/test.txt;type=i")
print(f)
print(e)

returns

Hello World!

nil

I believe this can be fixed in luasocket since curl and wget work somehow

codeninja-ru avatar Jun 19 '25 19:06 codeninja-ru

Does it work if you use the parameters in a table, instead of a single url as parameter to get? See https://lunarmodules.github.io/luasocket/ftp.html

imho a full url should not strip the leading /, since it refers to an absolute path, so this is a bug. But we should verify that if you pass a table of options, that we also don't strip the leading / if given.

Tieske avatar Jun 20 '25 09:06 Tieske

Does it work if you use the parameters in a table, instead of a single url as parameter to get? See https://lunarmodules.github.io/luasocket/ftp.html

No, it doesn't work this way either

codeninja-ru avatar Jun 20 '25 20:06 codeninja-ru

I think this code in ftp.lua

    local argument = sendt.argument or
        url.unescape(string.gsub(sendt.path or "", "^[/\\]", ""))

have to be replaced to

local argument = sendt.argument or url.unescape(sendt.path or "")

codeninja-ru avatar Jun 21 '25 16:06 codeninja-ru

I'd argue that if the path is omitted, it should default to /

Tieske avatar Jun 22 '25 20:06 Tieske