PASV ftp

Thu, Feb 27, 2003

My FTP code only supports PASV ftp right now. The reasoning is that I'm behind a NAT firewall and my server isn't. PASV works much better in that configuration. Chris is having problems getting my code to work and he is blaming this.

FTP generally has two TCP connections: a control connection and a data connection. The control connection is pretty straigtforward. You connect to port 21 and start sending messages back and forth. Some of these commands ask to open a data connection -- to upload a file, download a file or get a directory listing.

There are two ways to establish the data connection:

  1. Normal FTP: you can have the server establish the connection to your machine. You tell the server that you are listening on a certain port and that he should connect to you there.
  2. Passive FTP: you establish the connection to the server. You ask the server for another address/port and you initiate the connection.

In a world with network address translation (NAT) it is a lot easier to connect from your protected machine out to the network than it is to have another machine connect (on a new port) to you. This is why I did passive FTP. Doing normal FTP shouldn't be that hard if this is indeed the problem that Chris is having.

Oh yeah, and if both client and server are behind NAT, you are screwed. That is unless one of the NATs is smart enough to understand FTP and translate stuff along the way. HTTP can work better here since everyone understands it and it all happens on one socket. However, HTTP servers aren't set up for this type of thing without wacky extensions like WebDAV or the frontpage extensions.