Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how does ftpd determine that the STORed filed transfer is over? #167

Open
FerdinandoPH opened this issue Mar 4, 2023 · 4 comments

Comments

@FerdinandoPH
Copy link

I'm programming an FTP client for the 3ds. When I try to send a file to the server with STOR, and the file transfer is finished, I close the data port, but then I get an error [ERROR] recv: Connection reset by peer instead of the 226 command. I've tried delaying the closure of the data port, but with no luck. How am I supposed to tell ftpd that the STOR data transfer is overd?
I'm using ftpd 3.1.0 (not classic) on a new 3ds (3dsx, rosalina 2.4.1)

@mtheall
Copy link
Owner

mtheall commented Mar 4, 2023

Are you sure you closed only the data port and not the command port?

@FerdinandoPH
Copy link
Author

FerdinandoPH commented Mar 4, 2023

I'm pretty sure. Here is the code (Lua):

    function sendData(data)      
        if data_skt == nil then
            error("An error occurred during data sending.")
        end
        return Socket.send(data_skt, data)
    end

    function openDataSocket()
	consoleWrite("Opening data channel on port " ..data_port.. "...\n")
	data_skt = Socket.connect(ip, data_port, is_ssl)
    end

    function closeDataSocket()
        Socket.close(data_skt)
        data_skt = nil
    end

    (...)

   function storeFile(filename)
	sendResponsiveCommand("TYPE", "I")
	enterPassiveMode()
	sendCommand("STOR", filename)
	openDataSocket()
	recvResponse()
	--consoleClear()
	consoleWrite("Transfering " .. filename .. "...\n")
	input = io.open(client_dir..filename,FREAD)
	local filesize = io.size(input)
	local i = 0
	while i < filesize do
		packet_size = math.min(524288,filesize-i)
		i = i + sendData(io.read(input,i,packet_size))
	end
        consoleWrite("Transfer complete, now closing data socket on port " .. data_port .. "...\n")
	closeDataSocket()
	io.close(input)
	recvResponse()
	recvResponse()
	enterPassiveMode()
	listServerDirectory()
	need_refresh = true
    end

I've noticed that ftpd sends a 226 message when the transmission is over when I use FileZilla. Looking at the source code (specifically at ftpSession.cpp), I've noticed that that message is supposed to be sent when the buffer is 0. Maybe it has something to do with that?

@mtheall
Copy link
Owner

mtheall commented Mar 4, 2023

Yes, once you close the data socket then server side will get a read of zero which marks the end of the data transfer, which the server will then send the 226 response.
Can you show the logs of your transfer?

@FerdinandoPH
Copy link
Author

These are the logs of my client (1st) and ftpd (2nd)

WhatsApp Image 2023-03-04 at 23 35 45 (1)

WhatsApp Image 2023-03-04 at 23 35 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants