1
votes

I'm trying to implement a FTP client in PHP and I'm having problems with the active mode.

I'm not very very familiar with some points of socket programming.

The situation is this:

  1. I connect to the server and I authenticate
  2. I change to active mode by sending "PORT n1,n2,n3,n4,n5,n6"
  3. I create a server socket for incoming connection
  4. I send the command "RETR " so the server can connect to n5 * 256 + n6

What I don't know is how to create the server socket (3) and leave it working and expecting connection so I can send the RETR command (4).

If you can give me at least a point of view, it would be great.

Thanks in advance.

1
Why did you mark this as C++ and c?Paweł Stawarz

1 Answers

1
votes

3 is the easy part - you create a socket (socket_create) bind it to an address (socket_bind) then start to listen (socket_listen). The process is described on the socket_listen page in the manual.

However speaking as someone who has written FTP clients before, this is the least of your worries (you can actually save yourself the bother by simply setting PASV). What's really difficult is andling all the subtle differences between different implementations of the protocol - they vary hugely. Besides that FTP is fundamentally insecure - unless someone is holding a gun to your head, use HTTPS or SCP.