PHPackages                             dbeurive/ftp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. dbeurive/ftp

ActiveLibrary[HTTP &amp; Networking](/categories/http)

dbeurive/ftp
============

This package implements a simple FTP client with handy features

3.0.4(6y ago)014MITPHPPHP &gt;=5.6.0

Since Jan 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dbeurive/ftp)[ Packagist](https://packagist.org/packages/dbeurive/ftp)[ RSS](/packages/dbeurive-ftp/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

Introduction
============

[](#introduction)

This repository contains a wrapper around the (pretty good) PHP functionalities for FTP.

Synopsis
========

[](#synopsis)

```
$options = array(Ftp::OPTION_PORT => $port, Ftp::OPTION_TIMEOUT => 60);

$ftp = new Ftp($host, $options);
$ftp->connect();
$ftp->login($user, $password);

$ftp->get($local_path, $remote_path);
$ftp->put($local_path, $remote_path);
$ftp->delete($remote_path);
$ftp->mkdir($remote_path);
$entries = $ftp->ls($remote_path, true);

$status = $ftp->deleteIfExists($remote_path);
$status = $ftp->fileExists($remote_path);
$status = $ftp->directoryExists($remote_path);
$entry = $ftp->entryExists($remote_path);
$status = $ftp->mkdirRecursiveIfNotExist($remote_path);

$ftp->setEntryManagerClassName($your_own_class_name);

```

Installation
============

[](#installation)

From the command line:

```
composer require dbeurive/ftp

```

Or, from within the file composer.json:

```
"require": {
    "dbeurive/ftp": "*"
}

```

Documentation
=============

[](#documentation)

The code is heavily documented and there is a simple example for each method.

- **connect()**: Open a connexion to the server.
- **disconnect()**: Close the connexion to the server.
- **login($in\_user\_name, $in\_password)**: Authenticate to the server.
- **isLogged()**: Test whether the client has authenticated to the server.
- **ls($in\_opt\_dir='.', $in\_opt\_throw\_exception\_on\_error=false)**: List the content of a directory identified by its given path. This function parses the output returned by the server.
- **put($in\_local\_file\_path, $in\_remote\_file\_path, $in\_opt\_mode=FTP\_BINARY)**: Put a file from the local host to the remote server.
- **get($in\_local\_file\_path, $in\_remote\_file\_path, $in\_opt\_mode=FTP\_BINARY)**: Get a file from the remote server to the local host.
- **mkdir($in\_directory\_path)**: Create a directory on the remote host.
- **mkdirRecursiveIfNotExist($in\_directory\_path)**: Recursively create a directory identified by its given path, if the directory does not already exist.
- **rmdir($in\_directory\_path):** Remove a directory identified by its given path.
- **delete($in\_file\_path)**: Delete a file identified by its given path on the remote server.
- **deleteIfExists($in\_directory\_path)**: Test whether a file exists, and if it does, then delete it.
- **entryExists($in\_entry\_path)**: Test whether an entry (directory, file of link), identified by its given path, exists or not.
- **directoryExists($in\_directory\_path)**: Test whether a directory, identified by its given path, exists or not.
- **fileExists($in\_file\_path)**: Test whether a file, identified by its given path, exists or not.
- **setEntryManager($in\_class\_name)**: Set the name of the class that represents an entry (file, directory or link, on the remote host) and is responsible for parsing the output of the FTP command LIST.

The last method (`setEntryManager`) needs to be described with more details.

The FTP command LIST returns a text that represents the list of entries (directories, files or links) in the remote directory. For example:

```
-rw-r--r--    1 0        0               1 Jan 15 14:08 file0.txt
-rw-r--r--    1 0        0               2 Jan 15 14:08 file1.txt
-rw-r--r--    1 0        0               3 Jan 15 14:08 file2.txt
-rw-r--r--    1 0        0               4 Jan 15 14:08 file3.txt
drwxr-xr-x    2 0        0            4096 Jan 15 14:08 r1
drwxr-xr-x    2 0        0            4096 Jan 15 14:08 r2
drwxr-xr-x    2 0        0            4096 Jan 15 14:08 r3
drwxr-xr-x    2 0        0            4096 Jan 15 14:08 r4

```

Please note that:

- the organisation of the text returned by the FTP command LIST may vary from one OS to another, or from one FTP server to another.
- depending on the OS or the FTP server, the properties associated with the entries may not be identical.

However, this text must be parsed in order to extract the list of entries, along with their properties (permissions, owners, groups...).

It is not possible to handle all possible text organisations (for all OS and maybe, all FTP servers) and all possible properties.

Thus, the FTP wrapper lets the user the possibility to declare its own class that handles the parsing of the text and manages the properties. The default class used is [EntryManagerUnix](https://github.com/dbeurive/ftp/blob/master/src/EntryManagerUnix.php).

However, you can write and declare your own class to handle another use case. Your class must extends the abstract class [AbstractEntryManager](https://github.com/dbeurive/ftp/blob/master/src/AbstractEntryManager.php).

> You must set your entry manager **BEFORE** issuing any command that deals with entries (LIST...). You should set it right after you instantiate the Ftp object.

See [this example](https://github.com/dbeurive/ftp/blob/master/examples/set-entry-manager.php).

Unit tests
==========

[](#unit-tests)

In order to run the unit tests, you need the following elements:

- a host running an FTP server and an SSH server.
- access to the FTP server and to the SSH server.

> SSH is used to execute shell commands on the host that runs the FTP server. These commands will prepare the environment for the tests.

Preparation
-----------

[](#preparation)

### Edit tests/setenv.sh

[](#edit-testssetenvsh)

This script defines parameters used during the unit tests. These parameters are:

#### The parameters below used to (unit) test valid test cases

[](#the-parameters-below-used-to-unit-test-valid-test-cases)

- **FTP\_REMOTE\_HOST\_OK**: host name or IP address of the FTP server.
- **FTP\_USER\_OK**: user name used to authenticate to the FTP server.
- **FTP\_PASSWORD\_OK**: password used to authenticate to the FTP server.
- **FTP\_PORT\_OK**: TCP port used by the TP server (ex: 21).

#### The parameters used to (unit) test invalid test cases

[](#the-parameters-used-to-unit-test-invalid-test-cases)

- **FTP\_REMOTE\_HOST\_KO**: name or IP address of a host that does not listen for FTP connexion requests.
- **FTP\_USER\_KO**: invalid user name.
- **FTP\_PASSWORD\_KO**: invalid password
- **FTP\_PORT\_KO**: invalid TCP port number.
- **ROOT\_ON\_REMOTE**: *FTP path*, on the remote host (that runs the FTP server), used to get and put files through FTP.
- **BAD\_DIR\_ON\_REMOTE**: invalid *FTP path*, on the remote host (that runs the FTP server).

#### The parameters used to set up the environment on the host that run the FTP server

[](#the-parameters-used-to-set-up-the-environment-on-the-host-that-run-the-ftp-server)

- **SSH\_ARG**: command line argument(s) for the `ssh̀` command used to connect, through SSH, to the host that runs the FTP server.

Example:

```
export FTP_REMOTE_HOST_OK='10.11.12.13'
export FTP_USER_OK='good_ftp_user_name'
export FTP_PASSWORD_OK='goot_ftp_password'
export FTP_PORT_OK=21
export FTP_REMOTE_HOST_KO='yahoo.com'
export FTP_USER_KO='invalid_user_name'
export FTP_PASSWORD_KO='invalid password'
export FTP_PORT_KO=10021
export ROOT_ON_REMOTE='/files';
export BAD_DIR_ON_REMOTE='/tmp';
export SSH_ARG='root@127.0.0.1'

```

### Edit tests/clear\_on\_remote.sh

[](#edit-testsclear_on_remotesh)

The script `tests/clear_on_remote.sh` will be executed on the host that runs the FTP server. It will prepare the environment for the unit tests.

Set the correct value for **FTP\_REMOTE\_DIR**.

**FTP\_REMOTE\_DIR**: absolute *system path*, on the host that runs the server, used to get or put files through FTP.

Example:

```
FTP_REMOTE_DIR=/home/ftpuser/ftp/files

```

### Run the unit tests

[](#run-the-unit-tests)

Run the commands below:

```
. ./tests/setenv.sh
./vendor/bin/phpunit

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~71 days

Total

8

Last Release

2389d ago

Major Versions

1.0.1 → 2.0.02019-01-17

2.0.0 → 3.0.02019-01-18

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18211524?v=4)[Denis BEURIVE](/maintainers/dbeurive)[@dbeurive](https://github.com/dbeurive)

---

Top Contributors

[![dbeurive](https://avatars.githubusercontent.com/u/18211524?v=4)](https://github.com/dbeurive "dbeurive (33 commits)")

---

Tags

ftp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dbeurive-ftp/health.svg)

```
[![Health](https://phpackages.com/badges/dbeurive-ftp/health.svg)](https://phpackages.com/packages/dbeurive-ftp)
```

###  Alternatives

[league/uri

URI manipulation library

1.1k206.4M277](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[anchu/ftp

A simple Laravel 7 ftp service provider

225579.4k](/packages/anchu-ftp)[dg/ftp-php

Easy-to-use library for accessing FTP servers

201701.6k3](/packages/dg-ftp-php)[illuminate/http

The Illuminate Http package.

11936.0M5.1k](/packages/illuminate-http)[altayalp/ftp-client

FTP and SFTP client for Php

1971.3k](/packages/altayalp-ftp-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
