1. Go to this page and download the library: Download tomedio/php-ftp-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomedio / php-ftp-client example snippets
$ftp = new \FtpClient\FtpClient();
$ftp->connect($host);
$ftp->login($login, $password);
$ftp = new \FtpClient\FtpClient();
$ftp->connect($host, true, 990);
$ftp->login($login, $password);
// Upload with the BINARY mode
$ftp->putAll($sourceDirectory, $targetDirectory);
// Is equal to
$ftp->putAll($sourceDirectory, $targetDirectory, FTP_BINARY);
// Or upload with the ASCII mode
$ftp->putAll($sourceDirectory, $targetDirectory, FTP_ASCII);
// Size of the current directory
$size = $ftp->dirSize();
// Size of a given directory
$size = $ftp->dirSize('/path/of/directory');
// Count in the current directory
$total = $ftp->countItems();
// Or alias
$total = $ftp->count();
$items = $ftp->scanDir();
// scan the current directory (recursive) and returns the details of each item
var_dump($ftp->scanDir('.', true));
$ftp->put($localFile, $remoteFile);
$ftp->get($remoteFile, $localFile);
$ftp->delete($file);
$ftp->deleteDir($directory);
$ftp->makeDir($directory);
$ftp->rename($oldName, $newName);
$ftp->chmod($mode, $file);
$ftp->chown($owner, $file);
$ftp->chgrp($group, $file);
$ftp->mdtm($file);
$ftp->size($file);
$ftp->systype();
$ftp->pwd();
$ftp->chdir($directory);
$ftp->nlist();
$ftp->nlist($directory);
try {
// Code that may throw an exception
} catch (\FtpClient\FtpException $e) {
// Handle the exception
echo 'An error occurred: ' . $e->getMessage();
}