PHP Classes

PHP FTP Client Library: Manage files in remote FTP server

Recommend this page to a friend!
  Info   View files Documentation   View files View files (39)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2022-03-14 (Yesterday) RSS 2.0 feedNot enough user ratingsTotal: 136 This week: 17All time: 9,136 This week: 10Up
Version License PHP version Categories
lazzard-ftp-client 1.7.0MIT/X Consortium ...7.4Networking, Files and Folders, PHP 7
Description Author

This package provides classes and methods to manage your FTP files.

It provides several classes that can configure FTP server connection with various options, establish secure connections with SSL, and access files and directories available in the remote server.

The FTP client class also supports asynchronous download and upload of files.

It can invoke callback functions to process the results of a file upload and download asynchronously in a given interval of time.

Innovation Award
PHP Programming Innovation award nominee
December 2021
Number 3
FTP is a traditional protocol that applications use to transfer files between computers.

PHP provides an extension that can download or upload files synchronously. Therefore the PHP scripts need to wait for one upload and download operation to finish to start another file transfer operation.

This package provides an alternative approach that allows asynchronous file upload or download. This way, it is possible to request that the box performs multiple file transfer operations simultaneously.

Manuel Lemos
Picture of El Amrani Chakir
  Performance   Level  
Name: El Amrani Chakir <contact>
Classes: 3 packages by
Country: Morocco Morocco
Innovation award
Innovation award
Nominee: 2x

Details

Downloads Packagist Version tests Minimum PHP version License

Lazzard/FtpClient

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

<?php

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');
    $connection->open();

    $config = new FtpConfig($connection);
    $config->setPassive(true);

    $client = new FtpClient($connection);

    print_r($client->getFeatures());

    $connection->close();

} catch (Throwable $ex) {
    print_r($ex->getMessage());
}

Usage

upload/download

// 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.

listing

// get files names within an FTP directory
$client->listDir('path/to/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
$client->listDirDetails('path/to/directory');

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

copy

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

search

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

size

// get file size
$client->fileSize('path/to/file');

// get directory size
$client->dirSize('path/to/directory');

file/directory creating

// create an FTP file
$client->createFile('path/to/file');

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

// create a remote directory
// note: this method supports recursive directory creation
$client->createDir('directory');

append

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

remove/rename

// remove an FTP file
$client->removeFile('path/to/file');

// remove an FTP directory (be careful all the files within this directory will be removed)
$client->removeDir('path/to/directory');

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

move

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

count

// get the count of all the files within a directory
$client->getCount('path/to/directory');

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

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

permissions

// 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 ?
$client->isDir('path/to/file/or/directory');

// is a file type ?
$client->isFile('path/to/file/or/directory');

// is an empty file/directory ?
$client->isEmpty('path/to/file/or/directory');

// is exists on the FTP server ?
$client->isExists('path/to/file/or/directory');

// is the server support the size feature ?
$client->isFeatureSupported('SIZE');

others

// get the last modified time of the giving file (not working with directories)
$client->lastMTime('path/to/file');

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

// get all supported features by the FTP server
$client->getFeatures();

// get the server system
$client->getSystem();

// send a request to allocate a space of bytes for the next transfer operation
// some FTP servers requires this before transfer operations 
$client->allocateSpace(2048);

// prevent the server from closing the connection and keeping it alive
$client->keepAlive();

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/ConnectionInterface.md

[2]: docs/FtpConfig.md

[3]: docs/FtpClient.md

[4]: docs/FtpCommand.md

[5]: docs/FtpWrapper.md

[6]: docs/tests.md

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 |

[7]: https://github.com/lazzard/php-ftp-client/releases/tag/v1.0.2

[8]: https://github.com/lazzard/php-ftp-client/releases/tag/v1.1.0

[9]: https://github.com/lazzard/php-ftp-client/releases/tag/v1.5.3

[10]: https://github.com/lazzard/php-ftp-client/releases/tag/v1.6.1

[11]: https://github.com/lazzard/php-ftp-client/releases/tag/v1.7.0

Contribution

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="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_square.png"/>

License

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

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagedocs (6 files)
Files folder imagesrc (2 files, 4 directories)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me
Accessible without login Plain text file TODO.md Data Auxiliary data

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file tests.yml Data Auxiliary data

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Plain text file ConnectionInterface.md Data Auxiliary data
  Accessible without login Plain text file FtpClient.md Data Auxiliary data
  Accessible without login Plain text file FtpCommand.md Data Auxiliary data
  Accessible without login Plain text file FtpConfig.md Data Auxiliary data
  Accessible without login Plain text file FtpWrapper.md Data Auxiliary data
  Accessible without login Plain text file tests.md Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCommand (1 file)
Files folder imageConfig (1 file)
Files folder imageConnection (4 files)
Files folder imageException (5 files)
  Plain text file FtpClient.php Class Class source
  Plain text file FtpWrapper.php Class Class source

  Files folder image Files  /  src  /  Command  
File Role Description
  Plain text file FtpCommand.php Class Class source

  Files folder image Files  /  src  /  Config  
File Role Description
  Plain text file FtpConfig.php Class Class source

  Files folder image Files  /  src  /  Connection  
File Role Description
  Plain text file Connection.php Class Class source
  Plain text file ConnectionInterface.php Class Class source
  Plain text file FtpConnection.php Class Class source
  Plain text file FtpSSLConnection.php Class Class source

  Files folder image Files  /  src  /  Exception  
File Role Description
  Plain text file CommandException.php Class Class source
  Plain text file ConfigException.php Class Class source
  Plain text file ConnectionException.php Class Class source
  Plain text file FtpClientException.php Class Class source
  Plain text file WrapperException.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageintegration (4 files, 4 directories)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file config.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  integration  
File Role Description
Files folder imageCommand (1 file)
Files folder imageConfig (1 file)
Files folder imageConnection (2 files)
Files folder imagecontainer-files (1 file, 1 directory)
  Accessible without login Plain text file Dockerfile Data Auxiliary data
  Plain text file FtpClientTest.php Class Class source
  Plain text file FtpConnectionFactory.php Class Class source
  Plain text file FtpWrapperTest.php Class Class source

  Files folder image Files  /  tests  /  integration  /  Command  
File Role Description
  Plain text file FtpCommandTest.php Class Class source

  Files folder image Files  /  tests  /  integration  /  Config  
File Role Description
  Plain text file FtpConfigTest.php Class Class source

  Files folder image Files  /  tests  /  integration  /  Connection  
File Role Description
  Plain text file FtpConnectionTest.php Class Class source
  Plain text file FtpSSLConnectionTest.php Class Class source

  Files folder image Files  /  tests  /  integration  /  container-files  
File Role Description
Files folder imageetc (2 directories)
  Accessible without login Plain text file bootstrap.sh Data Auxiliary data

  Files folder image Files  /  tests  /  integration  /  container-files  /  etc  
File Role Description
Files folder imagepam.d (1 file)
Files folder imagevsftpd (1 file)

  Files folder image Files  /  tests  /  integration  /  container-files  /  etc  /  pam.d  
File Role Description
  Accessible without login Plain text file vsftpd_virtual Data Auxiliary data

  Files folder image Files  /  tests  /  integration  /  container-files  /  etc  /  vsftpd  
File Role Description
  Accessible without login Plain text file vsftpd.conf Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:136
This week:17
All time:9,136
This week:10Up
For more information send a message to info at phpclasses dot org.