PHPackages                             brick/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. brick/ftp

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

brick/ftp
=========

FTP client for PHP

0.2.0(6y ago)64682MITPHPPHP &gt;=7.2

Since Oct 16Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Brick\\Ftp
==========

[](#brickftp)

[![](https://raw.githubusercontent.com/brick/brick/master/logo.png)](https://raw.githubusercontent.com/brick/brick/master/logo.png)

An object-oriented FTP client for PHP.

[![Latest Stable Version](https://camo.githubusercontent.com/e24ae92f8d01f8a06500dceb09645243251d609c76d8ec8bf8450aa707df18c4/68747470733a2f2f706f7365722e707567782e6f72672f627269636b2f6674702f762f737461626c65)](https://packagist.org/packages/brick/ftp)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

Installation
------------

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require brick/ftp
```

Requirements
------------

[](#requirements)

This library requires PHP 7.2 or later, and the [ftp](https://www.php.net/manual/en/book.ftp.php) extension.

Project status &amp; release process
------------------------------------

[](#project-status--release-process)

This library is abandoned and will not receive further development.

Package contents
----------------

[](#package-contents)

This repo has only 3 classes, in the `Brick\Ftp` namespace:

- `FtpClient` is the main class to interact with an FTP server
- `FtpException` is thrown if any operation fails
- `FtpFileInfo` is returned when listing directories

Quickstart
----------

[](#quickstart)

### Connect &amp; log in

[](#connect--log-in)

```
use Brick\Ftp\FtpClient;
use Brick\Ftp\FtpException;

try {
    $client = new FtpClient();

    $host    = 'ftp.example.com'; // FTP server host name
    $port    = 21;                // FTP server port
    $ssl     = false;             // whether to open a secure SSL connection
    $timeout = 90;                // timeout in seconds

    $username = 'ftp-user';
    $password = 'p@ssw0rd';

    $client->connect($host, $port, $ssl, $timeout);
    $client->login($username, $password);

    // You usually want to set passive mode (PASV) on; see below for an explanation
    $client->setPassive(true);
} catch (FtpException $e) {
    // An error occurred!
}
```

**Only the host name is required** in `connect()`, the other values (port, SSL, timeout) are optional and default to the values above.

#### What's passive mode?

[](#whats-passive-mode)

Passive mode, known as the `PASV` FTP command, is a way to tell the server to open ports where the client can connect to, to upload/download a file.

By default (passive mode not enabled), the client would open a local port and request the server to connect back to the client instead.

This requires that the ports in question are not blocked by a firewall, and are directly open to the internet (no NAT, or using port forwarding). In practice, it's much easier to use passive mode as most FTP servers are already configured to support it.

#### Exception handling

[](#exception-handling)

As you've seen above, we wrap all calls to `FtpClient` methods in a try-catch block. We won't do this in subsequent examples below for conciseness, but you should catch `FtpException` in *every* call to `FtpClient` methods, or you application will exit with "Uncaught Exception" if any error occurs.

### Get the working directory

[](#get-the-working-directory)

```
echo $client->getWorkingDirectory(); // e.g. /home/ftp-user
```

### Set the working directory

[](#set-the-working-directory)

```
$client->setWorkingDirectory('/home/ftp-user/archive');
```

### List a directory

[](#list-a-directory)

```
$files = $client->listDirectory('.');

foreach ($files as $file) {
    // $file is an FtpFileInfo object
    echo $file->name, PHP_EOL;
}
```

Each value in the array returned by `listDirectory()` is an `FtpFileInfo` object. Depending on the capabilities of the FTP server, it may contain as little as only the file name, or additional information:

PropertyTypeNullable (optional)Description`$name``string`NoThe file name`$isDir``bool`*Yes*`true` for a directory, `false` for a file`$size``int`*Yes*The file size, in bytes`$creationTime``string`*Yes*The creation time`$lastModificationTime``string`*Yes*The last modification time`$uniqueId``string`*Yes*A unique identifier for the fileIf the server does not support the `MLSD` command, only the file name will be available. If the server does support this command, additional information will be available; which ones depends on the server. As a result, you should check if a property is `null` before attempting to use it, and act accordingly.

Creation time and last modification time, if available, will be in either of these formats:

- `YYYYMMDDHHMMSS`
- `YYYYMMDDHHMMSS.sss`

### Recursively list all files under a given directory

[](#recursively-list-all-files-under-a-given-directory)

This will traverse the given directory and all of its subdirectories, and return all files found.

Just like `listDirectory()`, the result is an array of `FtpFileInfo` objects, but the keys of the array are the path to the file, *relative to the given directory*.

```
$files = $client->recursivelyListFilesInDirectory('.');

foreach ($files as $path => $file) {
    echo $path, PHP_EOL; // a/b/c.txt
    echo $file->name, PHP_EOL; // c.txt
}
```

Please note that this depends on the ability for the client to differentiate between files and directories. As a result, if the server does not support the `MLSD` command, the result will always be an empty array.

Also, please be aware that depending on the number of files and directories, this method may take a long time to execute.

### Rename a file or a directory

[](#rename-a-file-or-a-directory)

```
$client->rename('old/path/to/file', 'new/path/to/file');
```

### Delete a file

[](#delete-a-file)

```
$client->delete('path/to/file');
```

### Remove a directory

[](#remove-a-directory)

```
$client->removeDirectory('path/to/directory');
```

The directory must be empty, or an exception is thrown.

### Get the size of a file

[](#get-the-size-of-a-file)

```
$size = $client->getSize('path/to/file'); // e.g. 123456
```

### Download a file

[](#download-a-file)

```
$client->download($localFile, $remoteFile);
```

- `$localFile` can be either a `string` containing the local file name, or a `resource` containing a file pointer
- `$remoteFile` is the path of the file on the FTP server

This method accepts 2 additional, optional parameters:

- `$mode`: `FTP_BINARY` (default) or `FTP_ASCII` (see below for an explanation)
- `$resumePos`: the position in the remote file to start downloading from (default `0`)

#### `FTP_BINARY` or `FTP_ASCII`?

[](#ftp_binary-or-ftp_ascii)

- `FTP_BINARY` transfers the file as is, without any modification, and is the default value.
- `FTP_ASCII` converts newlines in the file (assuming it's a text file) to the format expected by the target platform. You should usually not use this mode.

### Upload a file

[](#upload-a-file)

```
$client->upload($localFile, $remoteFile);
```

- `$localFile` can be either a `string` containing the local file name, or a `resource` containing a file pointer
- `$remoteFile` is the destination path of the file on the FTP server

This method accepts 2 additional, optional parameters:

- `$mode`: `FTP_BINARY` (default) or `FTP_ASCII` (see above for an explanation)
- `$startPos`: the position in the remote file to start uploading to (default `0`)

### Send a raw command

[](#send-a-raw-command)

If for any reason, you need to send a raw FTP command to the server, this method is for you. The result is an array of all lines in the response returned by the server.

Note that this method does not check if the server response contains an error code, it always returns the raw output.

```
$lines = $client->sendRawCommand('FEAT');

foreach ($lines as $line) {
    echo $line, PHP_EOL;
}
```

Sample response:

```
211- Extensions supported:
 AUTH TLS
 PBSZ
 PROT
 CCC
 SIZE
 MDTM
 REST STREAM
 MFMT
 TVFS
 MLST
 MLSD
 UTF8
211 End.

```

### Close the connection

[](#close-the-connection)

```
$client->close();
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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 ~25 days

Total

3

Last Release

2399d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (15 commits)")

---

Tags

ftpbrickftps

### Embed Badge

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

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

###  Alternatives

[league/uri

URI manipulation library

1.1k240.0M374](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

539238.7M41](/packages/league-uri-interfaces)[dg/ftp-php

Easy-to-use library for accessing FTP servers

202723.1k3](/packages/dg-ftp-php)[altayalp/ftp-client

FTP and SFTP client for Php

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

PHPackages © 2026

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