PHP Classes


Recommend this page to a friend!
  Classes of El Amrani Chakir  >  PHP FTP Client Library  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Read me
Class: PHP FTP Client Library
Manage files in remote FTP server
Author: By
Last change: Updated
Merge branch 'master' into 1.7
Date: 3 months ago
Size: 7,866 bytes


Class file image Download

Downloads Packagist Version tests Minimum PHP version License


This library provides helper classes and methods to manage your FTP files in an OOP way.

Note: This library aimed to be a full FTP/FTPS client solution for the old(^5.5)and newer PHP releases(^8.0)* that support FTP extension.*

Quick Start

composer require lazzard/php-ftp-client


require __DIR__ . '/vendor/autoload.php';

use Lazzard\FtpClient\Connection\FtpSSLConnection;
use Lazzard\FtpClient\Config\FtpConfig;
use Lazzard\FtpClient\FtpClient;

try {
    if (!extension_loaded('ftp')) {
        throw new \RuntimeException("FTP extension not loaded.");

    $connection = new FtpSSLConnection('host', 'username', 'password');

    $config = new FtpConfig($connection);

    $client = new FtpClient($connection);



} catch (Throwable $ex) {



// download a remote file
$client->download('path/to/remote/file', 'path/to/local/file');

// upload a local file to remote server
$client->upload('path/to/local/file', 'path/to/remote/file');

Asynchronous upload/download

// download a remote file asynchronously
$client->asyncDownload('path/to/remote/file', 'path/to/local/file', function ($state) {
    // do something every second while downloading this file
}, 1, FtpWrapper::BINARY);

// upload a remote file asynchronously
$client->asyncUpload('path/to/local/file', 'path/to/remote/file', function ($state) {
    // do something 
}, 1, FtpWrapper::BINARY);

Find more about asynchronous stuff here.


// get files names within an FTP directory

// get only directories
$client->listDir('path/to/directory', FtpClient::DIR_TYPE);

// get detailed information of each file within a remote directory including 
// the file path of each file

// recursively
$client->listDirDetails('path/to/directory', true);


// copy a remote file/directory to another directory
$client->copy('path/to/remote/source', 'path/to/remote/directory');

// copy a local file/directory to the server
$client->copyFromLocal('path/to/local/file', 'path/to/remote/directory'); 

// copy a remote file/directory to local machine
$client->copyToLocal('path/to/remote/source', 'path/to/local/directory'); 


// get all png files within the giving directory with their details
$client->find('/.*\.png$/i', 'path/to/directory'); 

// recursively
$client->find('/.*\.png$/i', 'path/to/directory', true); 


// get file size

// get directory size

file/directory creating

// create an FTP file

// create a file with content
$client->createFile('path/to/file', 'Hello world!!');

// create a remote directory
// note: this method supports recursive directory creation


// append the giving content to a remote file
$client->appendFile('path/to/file', $content);


// remove an FTP file

// remove an FTP directory (be careful all the files within this directory will be removed)

// rename an FTP file/directory
$client->rename('path/to/file', $newName);


// move an FTP file or directory to another folder
$client->move('path/to/file', 'path/to/directory');


// get the count of all the files within a directory

// recursively
$client->getCount('path/to/directory', true);

// recursively and files only
$client->getCount('path/to/directory', true, FtpClient::FILE_TYPE);


// set a permissions on the giving FTP file/directory 
$client->setPermissions('path/to/file', [
    'owner' => 'r-w', // read & write
    'group' => 'w',
    'world' => 'w-r-e'

// or you can use the UNIX file permission digits 
$client->setPermissions('path/to/file', 777);

is methods

// is an ftp directory ?

// is a file type ?

// is an empty file/directory ?

// is exists on the FTP server ?

// is the server support the size feature ?


// get the last modified time of the giving file (not working with directories)

// get a content of an FTP file
$client->getFileContent('path/to/file', FtpWrapper::ASCII);

// get all supported features by the FTP server

// get the server system

// send a request to allocate a space of bytes for the next transfer operation
// some FTP servers requires this before transfer operations 

// prevent the server from closing the connection and keeping it alive

You can see all available methods here.

More documentation

  • [Manipulate the FTP connection with ConnectionInterface.][1]
  • [Configure the connection instance with FtpConfig.][2]
  • [Start working with the base class FtpClient.][3]
  • [Sending FTP commands with FtpCommand.][4]
  • [How to use the FtpWrapper class directly.][5]
  • [Running the integration tests.][6]

[1]: docs/

[2]: docs/

[3]: docs/

[4]: docs/

[5]: docs/

[6]: docs/

Version Guidance

| Version | Status | Last Release | PHP Version | |:-------:|:------:|:------------:|:-----------:| | 1.0.x | EOL | [v1.0.2][7] | >= 5.5 | | 1.4.x | EOL | [v1.4.2][9] | >= 5.6 | | 1.5.x | EOL | [v1.5.3][9] | ^7.2 \| 8.0.* | | 1.6.x | EOL | [v1.6.1][10] | ^7.4 \| 8.0.* | | 1.7.x | Latest | [v1.7.0][11] | ^7.4 \| ^8.0 |







Feel free to fork this repo if you want to enhance it or adding new features, also reported some issues that may have you facing while using the library will be very appreciated, Thank you!

They support this project

<img width="150px" src=""/>


MIT License. please see the LICENSE FILE for more information.

For more information send a message to info at phpclasses dot org.