hytriutucx
hytriutucx

Reputation: 1634

Emulation of an active FTP connection using BSD Sockets

I am new to socket progamming and I am trying to implement a stripped down FTP like program. It uses two TCP connections, one as a control connection and other as a data connection. The problem is that I do not know how to use the sever to connect to the client's N+1 port using its port 20. Please refer here, to fund out more.

Upvotes: 0

Views: 363

Answers (2)

ankit jalori
ankit jalori

Reputation: 19

You should probably go through FTP RFC 959 to get all the details. Client needs to share data port to the server if it wants server to initiate data connection.

Upvotes: 0

caf
caf

Reputation: 239041

To create the active mode data connection, you:

  • Find the local address of the control connection with getsockname();
  • modify this address by changing the port number to 20;
  • create another socket with socket();
  • bind the new socket to the port 20 address created with bind();
  • connect the socket to the client's address/port with connect().

Note that the bind() will likely fail if your daemon is not running as root, because binding a low port number is a privileged operation.

Upvotes: 3

Related Questions