PHP code example of pecee / ftp-client

1. Go to this page and download the library: Download pecee/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/ */

    

pecee / ftp-client example snippets


$ftp = new \FtpClient\FtpClient();
$ftp->connect($host, $sslEnabled, $port);
$ftp->login($login, $password);

// upload with the BINARY mode
$ftp->uploadDirectory($sourceDirectory, $targetDirectory);

// Is equal to
$ftp->uploadDirectory($sourceDirectory, $targetDirectory, FTP_BINARY);

// or upload with the ASCII mode
$ftp->uploadDirectory($sourceDirectory, $targetDirectory, FTP_ASCII);

// size of the current directory
$size = $ftp->getDirectorySize();

// size of a given directory
$size = $ftp->getDirectorySize('/path/of/directory');

// count in the current directory
$total = $ftp->count();

// count in a given directory
$total = $ftp->count('/path/of/directory');

// count only the "files" in the current directory
$total_file = $ftp->count('.', 'file');

// count only the "files" in a given directory
$total_file = $ftp->count('/path/of/directory', 'file');

// count only the "directories" in a given directory
$total_dir = $ftp->count('/path/of/directory', 'directory');

// count only the "symbolic links" in a given directory
$total_link = $ftp->count('/path/of/directory', 'link');

// scan the current directory and returns the details of each item
$items = $ftp->scanDirectory();

// scan the current directory (recursive) and returns the details of each item
var_dump($ftp->scanDirectory('.', true));

// 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->deleteFile('path/of/directory/to/remove');

// Removes a directory (recursive)
$ftp->deleteDirectory('path/of/directory/to/remove', true);

// Creates a directory
$ftp->createDirectory('path/of/directory/to/create');

// Creates a directory (recursive),
// creates automaticaly the sub directory if not exist
$ftp->createDirectory('path/of/directory/to/create', true);

// and more ...

var_dump($ftp->help());

// 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');