oihana / php-ftp
The Oihana PHP FTP library - a modern, strongly-typed FTP/FTPS client
Requires
- php: >=8.4
- ext-ftp: *
- ext-openssl: *
- oihana/php-core: dev-main
- oihana/php-enums: dev-main
- oihana/php-files: dev-main
- oihana/php-logging: dev-main
- oihana/php-reflect: dev-main
Requires (Dev)
- nunomaduro/collision: ^8.8
- phpdocumentor/shim: ^3.8
- phpunit/phpunit: ^13
Suggests
- ext-sodium: Recommended for reliable in-memory credential wiping (sodium_memzero()). Without it, the library falls back to overwriting the buffer with NUL bytes.
- psr/log: Inject a PSR-3 logger to trace connection, transfer and retry events.
README
A modern, strongly-typed FTP / FTPS client for PHP 8.4+, built in the spirit of the oihana/php-* libraries.
📚 Documentation
User guides (FR + EN), with narrative explanations, examples and security notes:
| 🇬🇧 English documentation | 🇫🇷 Documentation française |
| Getting started, connection, transfers, directories, encryption, architecture, security, testing. | Démarrage, connexion, transferts, répertoires, chiffrement, architecture, sécurité, tests. |
Auto-generated API reference (phpDocumentor):
👉 https://bcommebois.github.io/oihana-php-ftp
🚀 Features
- 🔌 FTP & FTPS (explicit TLS) over the native
ext-ftpextension — zero runtime dependencies. - 🧩 Trait-composed client with a clean, mockable driver layer (
FtpDriverInterface) — SFTP-ready by design. - 🔑 Authentication & security as first-class concerns: credentials are wiped from memory, secrets are never logged.
- 📁 File & directory operations: upload, download, append, delete, rename, listing (MLSD/raw),
chmod, recursive helpers. - 🧱 Constant enums everywhere — no magic strings for config keys, transfer modes or connection options.
- 🪵 PSR-3 logging (optional) with retry + exponential backoff on transient failures.
- 🔐 Seamless reuse of
oihana/php-filespath/MIME helpers and OpenSSL file encryption. - 🧪 Full unit-test coverage through the mockable driver — no live server required.
💡 Designed to be lightweight, testable, and compatible with any PHP 8.4+ project.
📦 Installation
Requires PHP 8.4+ with the
ext-ftpextension.
Install via Composer:
composer require oihana/php-ftp
⚡ Usage
use oihana\ftp\FtpClient ; use oihana\ftp\enums\Ftp ; use oihana\ftp\enums\FtpSecurity ; $client = new FtpClient ([ Ftp::HOST => 'ftp.example.org' , Ftp::USERNAME => 'alice' , Ftp::PASSWORD => 's3cr3t' , Ftp::SECURITY => FtpSecurity::SSL , // FTPS over TLS Ftp::ROOT => '/public' , // chdir right after login ]) ; $client->connect() ; // Transfers $client->upload( '/local/report.pdf' , 'report.pdf' ) ; $client->download( 'archive.tar.gz' , '/local/archive.tar.gz' ) ; // Encrypted transfer (OpenSSL, via oihana/php-files) $client->uploadEncrypted( '/local/secret.txt' , 'secret.enc' , 'pass-phrase' ) ; // Directory listing (structured, MLSD with ls -l fallback) foreach ( $client->listFiles( '/public' ) as $file ) { echo $file->name , $file->isDirectory() ? '/' : '' , PHP_EOL ; } $client->disconnect() ;
All transport calls go through
FtpDriverInterface. Inject your own driver as the second constructor argument to unit-test against an in-memory fake, or to plug in an alternative transport later.
✅ Tests & coverage
Run the full unit-test suite (PHPUnit, strict mode):
composer test
Measure coverage (requires Xdebug or PCOV):
composer coverage # text + Clover + HTML under build/coverage/ composer coverage:md # readable Markdown summary (build/coverage/COVERAGE.md)
All transport calls go through FtpDriverInterface, so the suite reaches full
coverage by mocking an in-memory driver — no real FTP server is needed. See
CONTRIBUTING.md for the testing philosophy.
🧾 License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
👤 About the author
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🛠️ Generate the Documentation
We use phpDocumentor to generate the API documentation into the ./docs folder.
composer doc
🔗 Related packages
oihana/php-files– file, path and OpenSSL helpers reused by this library:https://github.com/BcommeBois/oihana-php-filesoihana/php-core– core helpers and utilities:https://github.com/BcommeBois/oihana-php-coreoihana/php-reflect– reflection and hydration utilities:https://github.com/BcommeBois/oihana-php-reflectoihana/php-enums– strongly-typed constant enumerations for PHP:https://github.com/BcommeBois/oihana-php-enums
