An FTP wrapper class for file handling in PHP

Some time ago, I had to develop a system for handling a large amount of CSV files that were automatically being uploaded to an FTP location. As it was an automated system, I needed a class flexible enough to handle a lot of the common ftp functions I would be making use of. It also contains a couple of additional functions that were more specific to my needs. The latest_file method will take the latest file from the current directory based on the date the file was last modified. This was pretty essential to my needs at the time as the directory was being filled with new CSV files on a regular basis and were irregularly named, so I had to ensure I was only taking the latest file.

The class is also able to make several connection attempts to an FTP, which you can modify using the methods set_attempts and set_delay, which sets the delay between attempts in seconds.

Here’s a basic usage example;

Here is the entire class;

Leave a Reply

Your email address will not be published. Required fields are marked *