I recently battled downloading a large (500+ MB) file via PHP’s native FTP functions. I tried several methods, including
ftp_nb_continue, but I was continuously receiving error messages. The messages themselves are next to useless in determining the root cause of the problem, so I thought I’d share with you my solutions here. Below are examples of the messages I was receiving:
- Warning: ftp_get(): Opening BINARY mode data connection for [filename]
- Warning: ftp_nb_continue(): Opening BINARY mode data connection for [filename]
Ultimately I devised a solution utilizing recursion that allowed for auto resuming of downloads that had previously failed. I set a maximum number of download attempts to an arbitrary amount, 5. Note that I also included support for turning FTP’s
PASV mode on, as this seems to fix problems for certain individuals right out of the gate. You may notice the command being sent if you use your favorite FTP client, i.e. Filezilla.