Authored by Corey Ballou

FTP File Downloads with Auto Resume in PHP

I recently battled downloading a large (500+ MB) file via PHP’s native FTP functions. I tried several methods, including ftp_get and 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.

Author: Corey Ballou

Corey Ballou is the CEO of Whether you're a student, young professional, entrepreneur, startup, or small business, you can be up and online fast with your own custom domain, email, and webpage on POP. Corey is a professional PHP developer by trade, specializing in custom web applications development for startups, small businesses, and agencies. Follow Corey on Twitter @cballou.