I'm working on a simple ftp server in c. I don't know when ftp server accepts passive data connection from client. To my understanding here is how passive ftp works:
- client sends "PASV" command to server
- server creates and binds a socket, and listens on a random port.
- server uses getsockname to get random port
- assemble passive reply message in format: 227 Entering Passive Mode(a1,a2,a3,a4,a5,a6). Note: server ip is a1.a2.a3.a4 and port number is: a5 * 256 + a6.
my question is: when does ftp server accepts the connection to said random port? should server accept data connection after sending reply? or should ftp server accept connection right before data connection is required, i.e. when client is requesting a file?
I have RFC959. is there any other useful ftp resource out there? google is not particularly helpful.
thanks in advance