MatTheCat
MatTheCat

Reputation: 18761

Strange PHP’s FTP wrapper behavior

Using fopen on a remote FTP file results in

failed to open stream: Failed to set up data channel: Connection refused

Filtering network trafic to FTP with Wireshark I see

Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
Request: USER user
Response: 331 User user OK. Password required
Request: PASS password
Response: 230 OK. Current restricted directory is /
Request: TYPE I
Response: 200 TYPE is now 8-bit binary
Request: SIZE filename
Response: 213 28344
Request: EPSV
Response: 229 Extended Passive mode OK (|||25127|)
Request: RETR filename

Following are some DNS queries then these TCP frames:

60662 → 25127 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=475196536 TSecr=0 WS=128
25127 → 60662 [RST, ACK] Seq=1 Ack=1 Win=0 Len=0
45764 → 21 [FIN, ACK] Seq=102 Ack=493 Win=64128 Len=0 TSval=475196552 TSecr=2527041209

Without using the wrapper I get

Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
Request: USER user
Response: 331 User user OK. Password required
Request: PASS password
Response: 230 OK. Current restricted directory is /
Request: PASV
Response: 227 Entering Passive Mode (89,31,148,62,184,87)
Request: TYPE A
Response: 200 TYPE is now ASCII
Request: RETR filename
Response: 150-Accepted data connection
Response: 226-File successfully transferred
Response: 226 Logout.

Seems like an issue with EPSV then?

Upvotes: 0

Views: 193

Answers (1)

MatTheCat
MatTheCat

Reputation: 18761

Sooo I guess my issue is the same as https://bugs.php.net/bug.php?id=69580

PHP’s FTP wrapper uses EPSV, while ftp_pasv uses PASV with IPv4. The server I try to download from has an issue with EPSV and the wrapper won’t fallback to PASV, hence the error.

One could ask the server’s administrator to fix their setup but in my case that just means I won’t be able to use the wrapper.

Upvotes: 1

Related Questions