PHP FTP Utilities
PHP FTP Utilities, (*1)
If you also need SFTP : php-sftp, (*2)
Install package with composer, (*3)
composer require hugsbrugs/php-ftp
In your PHP code, load librairy, (*4)
require_once __DIR__ . '/vendor/autoload.php'; use Hug\Ftp\Ftp as Ftp;
Test FTP connection, (*5)
Ftp::test($server, $user, $password, $port = 21);
Check if a file exists on Ftp Server, (*6)
Ftp::is_file($server, $user, $password, $remote_file, $port = 21);
Delete a file on remote FTP server, (*7)
Ftp::delete($server, $user, $password, $remote_file, $port = 21);
Recursively deletes files and folder in given directory (If remote_path ends with a slash delete folder content otherwise delete folder itself), (*8)
Ftp::rmdir($server, $user, $password, $remote_path, $port = 21);
Recursively copy files and folders on remote FTP server (If local_path ends with a slash upload folder content otherwise upload folder itself), (*9)
Ftp::upload_dir($server, $user, $password, $local_path, $remote_path, $port = 21);
Download a file from remote Ftp server, (*10)
Ftp::download($server, $user, $password, $remote_file, $local_file, $port = 21);
Download a directory from remote FTP server (If remote_dir ends with a slash download folder content otherwise download folder itself), (*11)
Ftp::download_dir($server, $user, $password, $remote_dir, $local_dir, $port = 21);
Rename a file on remote FTP server, (*12)
Ftp::rename($server, $user, $password, $old_file, $new_file, $port = 21);
Create a directory on remote FTP server, (*13)
Ftp::mkdir($server, $user, $password, $directory, $port = 21);
Create a file on remote FTP server, (*14)
Ftp::touch($server, $user, $password, $remote_file, $content, $port = 21);
Upload a file on FTP server, (*15)
Ftp::upload($server, $user, $password, $local_file, $remote_file = '', $port = 21);
List files on FTP server, (*16)
Ftp::scandir($server, $user, $password, $path, $port = 21);
Get default login FTP directory aka pwd, (*17)
Ftp::pwd($server, $user, $password, $port = 21);
Edit example/test.php with your FTP parameters then run, (*18)
php example/test.php
PHPUnit Tests, (*19)
Hugo Maugey visit my website ;), (*20)