Ftp client php open source
A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files. This package is aimed to remain simple and light. It's only a wrapper of the FTP native API of PHP, with some useful helpers. If you want to customize some methods, you can do this by inheriting one of the
3 classes of the package.
Getting StartedConnect to a server FTP : $ftp = new \FtpClient\FtpClient(); $ftp->connect($host); $ftp->login($login, $password); OR Connect to a server FTP via SSL (on port 990 or another port) : $ftp = new \FtpClient\FtpClient(); $ftp->connect($host, true, 990); $ftp->login($login, $password); Note: The connection is implicitly closed at the end of script execution (when the object is destroyed). Therefore it is unnecessary to call UsageUpload all files and all directories is easy : // upload with the BINARY mode $ftp->putAll($source_directory, $target_directory); // Is equal to $ftp->putAll($source_directory, $target_directory, FTP_BINARY); // or upload with the ASCII mode $ftp->putAll($source_directory, $target_directory, FTP_ASCII); Note : FTP_ASCII and FTP_BINARY are predefined PHP internal constants. Get a directory size : // size of the current directory $size = $ftp->dirSize(); // size of a given directory $size = $ftp->dirSize('/path/of/directory'); Count the items in a directory : // count in the current directory $total = $ftp->countItems(); // or alias $total = $ftp->count(); // count in a given directory $total = $ftp->countItems('/path/of/directory'); // count only the "files" in the current directory $total_file = $ftp->countItems('.', 'file'); // count only the "files" in a given directory $total_file = $ftp->countItems('/path/of/directory', 'file'); // count only the "directories" in a given directory $total_dir = $ftp->countItems('/path/of/directory', 'directory'); // count only the "symbolic links" in a given directory $total_link = $ftp->countItems('/path/of/directory', 'link'); Detailed list of all files and directories : // scan the current directory and returns the details of each item $items = $ftp->scanDir(); // scan the current directory (recursive) and returns the details of each item var_dump($ftp->scanDir('.', true)); Result:
All FTP PHP functions are supported and some improved : // Requests execution of a command on the FTP server $ftp->exec($command); // Turns passive mode on or off $ftp->pasv(true); // Set permissions on a file via FTP $ftp->chmod(0777, 'file.php'); // Removes a directory $ftp->rmdir('path/of/directory/to/remove'); // Removes a directory (recursive) $ftp->rmdir('path/of/directory/to/remove', true); // Creates a directory $ftp->mkdir('path/of/directory/to/create'); // Creates a directory (recursive), // creates automaticaly the sub directory if not exist $ftp->mkdir('path/of/directory/to/create', true); // and more ... Get the help information of remote FTP server : Result :
Note : The result depend of FTP server. ExtendCreate your custom // MyFtpClient.php /** * My custom FTP Client * @inheritDoc */ class MyFtpClient extends \FtpClient\FtpClient { public function removeByTime($path, $timestamp) { // your code here } public function search($regex) { // your code here } } // example.php $ftp = new MyFtpClient(); $ftp->connect($host); $ftp->login($login, $password); // remove the old files $ftp->removeByTime('/www/mysite.com/demo', time() - 86400); // search PNG files $ftp->search('/(.*)\.png$/i'); API docSee the source code for more details. It is fully documented 📘 TestingTested with "atoum" unit testing framework. LicenseMIT c) 2014, Nicolas Tallefourtane. Author
|