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

ActiveLibrary

antilam/ftp-client
==================

FTP and SFTP client for Php

1.0.0(9y ago)022MITPHPPHP &gt;=5.4.0

Since Aug 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Antilamer/php-ftp-client)[ Packagist](https://packagist.org/packages/antilam/ftp-client)[ Docs](https://github.com/altayalp/php-ftpclient)[ RSS](/packages/antilam-ftp-client/feed)WikiDiscussions master Synced 1mo ago

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

PHP FTP Client Library
======================

[](#php-ftp-client-library)

[![Build Status](https://camo.githubusercontent.com/704f6b793b20ac756175f47c7a23ce833d1e118ed6494cfcfdbc2740a900f355/68747470733a2f2f7472617669732d63692e6f72672f616e74696c616d2f7068702d6674702d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/antilam/php-ftp-client)[![Latest Stable Version](https://camo.githubusercontent.com/0ef08cbf30426aa4d61c28a2ec217400d59b7ae818da7574c805b9d83545336e/68747470733a2f2f706f7365722e707567782e6f72672f616e74696c616d2f6674702d636c69656e742f76657273696f6e)](https://packagist.org/packages/antilam/ftp-client)[![Latest Unstable Version](https://camo.githubusercontent.com/0e1499e2ba8db88d334893e415f7612f09cc2ba4a3b51c787b4093393e7b4937/68747470733a2f2f706f7365722e707567782e6f72672f616e74696c616d2f6674702d636c69656e742f762f756e737461626c65)](//packagist.org/packages/antilam/ftp-client)[![License](https://camo.githubusercontent.com/1fc8222f10158d1ebcac06510bdec78ef04c8ab1cb3d9863e584692d4b2bb4de/68747470733a2f2f706f7365722e707567782e6f72672f616e74696c616d2f6674702d636c69656e742f6c6963656e7365)](https://packagist.org/packages/antilam/ftp-client)

Php 5.4+ object oriented and unit tested library for FTP and SFTP (ssh ftp) process.

### Installation

[](#installation)

Make sure the [PHP FTP](http://php.net/book_ftp) extension is installed or enabled.

The recommended way to install the library is through [composer](https://getcomposer.org/).

```
composer require antilam/ftp-client
```

This command will install the library on current dir.

Usage
-----

[](#usage)

### Connect and Log in to Server

[](#connect-and-log-in-to-server)

```
// connect to ftp server
use antilam\FtpClient\Servers\FtpServer;

$server = new FtpServer('ftp.example.com');
$server->login('user', 'password');

// or connect to ssh server
use antilam\FtpClient\Servers\SftpServer;

$server = new SftpServer('ssh.example.com');
$server->login('user', 'password');
```

You can call SftpServer class by port or FtpServer class by the port and timeout. The default port for SFTP is 22, for FTP is 21 and for timeout is 90 seconds.

```
// connect to ftp server
use antilam\FtpClient\Servers\FtpServer;

$server = new FtpServer('ftp.example.com', 21, 90);
$server->login('user', 'password');

// or connect to ssh server
use antilam\FtpClient\Servers\SftpServer;

$server = new SftpServer('ssh.example.com', 22);
$server->login('user', 'password');
```

You can use same methods for FTP and SFTP after login server. The factory classes will return file or directory class instance.

If you have a problem login to FTP server, turnPassive() method may useful after login method. It's not exist for SFTP.

```
$server->turnPassive();
```

### Fetching Files

[](#fetching-files)

```
use antilam\FtpClient\FileFactory;

$file = FileFactory::build($server);
$list = $file->ls('public_html');
print_r($list);
```

Will output:

```
Array
(
    [0] => index.php
    [1] => .gitignore
    [2] => .htaccess
    [3] => composer.json
    [4] => phpunit.xml
    [5] => robots.txt
    [6] => server.php
)
```

This method takes two more optional parameters. $recursive also fetch subdirectories. $ignore parameter determine extension of the files which you don't want to see in list.

```
$list = $file->ls('public_html' false, array('php','html'));
```

Will output:

```
Array
(
    [0] => .gitignore
    [1] => .htaccess
    [2] => composer.json
    [3] => phpunit.xml
    [4] => robots.txt
)
```

### Fetching Directories

[](#fetching-directories)

```
use antilam\FtpClient\DirectoryFactory;

$dir = DirectoryFactory::build($server);
$list = $dir->ls('public_html');
print_r($list);
```

Will output:

```
Array
(
    [0] => app
    [1] => bootstrap
    [2] => css
    [3] => packages
    [4] => vendor
)
```

This method takes two more optional parameters. $recursive also fetch subdirectories. $ignore parameter determine name of the directories which you don't want to see in list.

```
$list = $dir->ls('public_html' false, array('packages','vendor'));
print_r($list);
```

Will output:

```
Array
(
    [0] => app
    [1] => bootstrap
    [2] => css
)
```

### Other File Operations

[](#other-file-operations)

**Download file from server to local disc with rename**

```
$file->download('public_html/remote.html', 'local.html');
```

**Upload file from local to server with rename**

```
$file->upload('local.zip', 'public_html/remote.zip');
```

**Upload file from http server to server**

```
$file->wget('http://www.example.com/remote.zip', 'public_html/remote.zip');
```

**Rename file to server**

```
$file->rename('public_html/oldname.zip', 'public_html/newname.zip');
```

**Change chmod file to server**

```
$file->chmod(0777, 'public_html/file.zip');
```

**Remove file to server**

```
$file->rm('public_html/remote.zip');
```

**Get last modified time to file**

```
$file->getLastMod('public_html/remote.zip');
```

**Get size to file**

```
$file->getSize('public_html/remote.zip');
```

### Other Directory Operations

[](#other-directory-operations)

**Create new directory**

```
$dir->mkdir('public_html/new_directory');
```

**Change current working directory**

```
$dir->cd('public_html/new_directory');
```

**Changes to the parent directory (not exist Sftp)**

```
$dir->cdUp();
```

**Get current working directory**

```
$dir->pwd();
```

**Rename Directory**

```
$dir->rename('public_html/oldname', 'public_html/newname');
```

**Change chmod directory to server**

```
$dir->chmod(0777, 'public_html/directory');
```

**Remove Directory**

The directory must be empty.

```
$dir->rm('public_html/directory');
```

### Usage Of Helper Class

[](#usage-of-helper-class)

Helper Class contains some useful methods for actions:

- Helper::formatByte: Format file size to human readable
- Helper::formatDate: Format unix time
- Helper::getFileExtension: Get given file extension
- Helper::newName: If exist local file, rename the file

```
Helper::formatByte($file->getSize('public_html/dashboard.zip'));
// Will output: 32.47 Mb
Helper::formatDate($file->getLastMod('public_html/dashboard.zip'));
// Will output: 14.06.2016 23:31
// or
Helper::formatDate($file->getLastMod('public_html/dashboard'), 'd.m.Y');
// Will output: 14.06.2016
Helper::getFileExtension($fileName);
// Will output: html
$file->download('public_html/demo.html', Helper::newName('demo.html'));
// if exist local file, rename file
// demo.html renamed to demo_dae4c9057b2ea5c3c9e96e8352ac28f0c7d87f7d.html
```

### Test

[](#test)

Firstly rename phpunit.xml.dist to phpunit.xml and than open the file to edit ftp variables. After run the phpunit command.

```
phpunit tests/Ftp
# or
phpunit tests/Sftp
```

### License

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/antilam/php-ftp-client/blob/master/LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 78.4% 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

Unknown

Total

1

Last Release

3566d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f5ff332787f72a635620852410f831f5b836ec3031617d6a82e7b0b5335fe6e?d=identicon)[Antilam](/maintainers/Antilam)

---

Top Contributors

[![altayalp](https://avatars.githubusercontent.com/u/3314135?v=4)](https://github.com/altayalp "altayalp (29 commits)")[![nazar-k](https://avatars.githubusercontent.com/u/6726208?v=4)](https://github.com/nazar-k "nazar-k (8 commits)")

---

Tags

ftpsshsftpftp-clientssh-ftpphp ftp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k434.8M1.3k](/packages/phpseclib-phpseclib)[altayalp/ftp-client

FTP and SFTP client for Php

1971.3k](/packages/altayalp-ftp-client)[nicolab/php-ftp-client

A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.

6435.3M24](/packages/nicolab-php-ftp-client)[dg/ftp-deployment

A tool for automated deployment of web applications to an FTP server.

615845.5k8](/packages/dg-ftp-deployment)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)

PHPackages © 2026

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