10

i'm writing an FTP server, but i don't understand the PASV command, any server sends a response like this:

227 Entering Passive Mode (213,229,112,130,216,4)

what does the numbers in brackets mean? And whats the difference between normal and passive mode?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
BackSlash
  • 21,927
  • 22
  • 96
  • 136
  • 1
    You should also read [the relevant RFC (959)](https://tools.ietf.org/html/rfc959). – Joachim Sauer Jan 24 '13 at 09:56
  • You should get really familiar with RFC 959 http://www.ietf.org/rfc/rfc959.txt This is the bible for FTP. There is a section that describes the result of a PASV request. – Peter Wooster Jan 24 '13 at 09:58
  • 1
    RFC 959 does not define a **standardized format** for the `PASV` response text, and that is acknowledged by [RFC 1123 Section 4.1.2.6](http://tools.ietf.org/html/rfc1123#page-31). Some FTP servers over the years have implemented their own formats. *Usually* the IP/Port is wrapped in parenthesis, but that is [not a guarantee](http://stackoverflow.com/a/22544828/65863). The `EPSV` command defined in [RFC 2428](http://tools.ietf.org/html/rfc2428) introduced a standardized format. – Remy Lebeau Mar 21 '14 at 00:38

2 Answers2

18

Yes, you've got (213,229,112,130,216,4) as a result. 213,229,112,130 is IP address. 216 is upper 8bits in decimal. 4 is lower 8bits in decimal. So port number is 216 * 256 + 4. You should parse them in bracket.

inherithandle
  • 2,614
  • 4
  • 31
  • 53
1

You can see what the numbers mean in RFC959 4.1.2 DATA PORT (PORT)

I couldn't find a site where I could deep link to the exact spot so you'll have to look for DATA PORT (PORT) in there.

If you look at the response as having format (h1,h2,h3,h4,p1,p2) then h1-h4 are is the IP address the server is asking the client to connect to for the data channel. e.g. 213.229.112.130

p1 and p2 are together the port number. It's a 16 bit number split into 2 8 bit parts, so to reconstruct it you do (p1 * 256 + p2) e.g. port: 55300

Though as mentioned above the exact format of the PASV command it is not guaranteed

Niko P
  • 45
  • 4