PHP code example of tomedio / php-ftp-client

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();
}
bash
composer 
text
'directory#public' =>
    array (size=10)
      'permissions' => string 'drwxr-xr-x' (length=10)
      'number'      => string '2' (length=1)
      'owner'       => string '1000' (length=4)
      'group'       => string 'staff' (length=5)
      'size'        => string '4096' (length=4)
      'month'       => string 'Dec' (length=3)
      'day'         => string '12' (length=2)
      'time'        => string '10:15' (length=5)
      'name'        => string 'public' (length=6)
      'type'        => string 'directory' (length=9)

'link#public/logo.png' =>
    array (size=11)
      'permissions' => string 'lrwxrwxrwx' (length=10)
      'number'      => string '1' (length=1)
      'owner'       => string '1000' (length=4)
      'group'       => string 'staff' (length=5)
      'size'        => string '20' (length=2)
      'month'       => string 'Dec' (length=3)
      'day'         => string '10' (length=2)
      'time'        => string '09:30' (length=5)
      'name'        => string 'logo.png' (length=8)
      'type'        => string 'link' (length=4)
      'target'      => string '/var/www/shared/logo.png' (length=24)

'file#public/index.php' =>
    array (size=10)
      'permissions' => string '-rw-r--r--' (length=10)
      'number'      => string '1' (length=1)
      'owner'       => string '1000' (length=4)
      'group'       => string 'staff' (length=5)
      'size'        => string '1234' (length=4)
      'month'       => string 'Dec' (length=3)
      'day'         => string '12' (length=2)
      'time'        => string '10:15' (length=5)
      'name'        => string 'index.php' (length=9)
      'type'        => string 'file' (length=4)