PHPackages                             altayalp/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. [HTTP &amp; Networking](/categories/http)
4. /
5. altayalp/ftp-client

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

altayalp/ftp-client
===================

FTP and SFTP client for Php

1.0.0(9y ago)1971.3k—7.9%15[2 issues](https://github.com/altayalp/php-ftp-client/issues)[2 PRs](https://github.com/altayalp/php-ftp-client/pulls)MITPHPPHP &gt;=5.4.0CI failing

Since Aug 5Pushed 4y ago1 watchersCompare

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

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

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

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

[![Build Status](https://camo.githubusercontent.com/1341efce6ea19f8e0038f887dca8e88e384cc368d8eb16a6b9fb7a164ca21d96/68747470733a2f2f7472617669732d63692e6f72672f616c746179616c702f7068702d6674702d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/altayalp/php-ftp-client)[![Latest Stable Version](https://camo.githubusercontent.com/80ee72bdeb07a0bfdb4d9a7e4abc1dda21d67ec06761ceee2a57b86f200fbc36/68747470733a2f2f706f7365722e707567782e6f72672f616c746179616c702f6674702d636c69656e742f76657273696f6e)](https://packagist.org/packages/altayalp/ftp-client)[![Latest Unstable Version](https://camo.githubusercontent.com/2f0b265d97fb99a1150cc235cec98534af71dddc969eace12d89cb1c75e3625b/68747470733a2f2f706f7365722e707567782e6f72672f616c746179616c702f6674702d636c69656e742f762f756e737461626c65)](//packagist.org/packages/altayalp/ftp-client)[![License](https://camo.githubusercontent.com/0b2fc557aee2913ffdfe903a35425ae09949a3861718630f659c7ff11592e443/68747470733a2f2f706f7365722e707567782e6f72672f616c746179616c702f6674702d636c69656e742f6c6963656e7365)](https://packagist.org/packages/altayalp/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 altayalp/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 altayalp\FtpClient\Servers\FtpServer;

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

// or connect to ssh server
use altayalp\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 altayalp\FtpClient\Servers\FtpServer;

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

// or connect to ssh server
use altayalp\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 altayalp\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 altayalp\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/altayalp/php-ftp-client/blob/master/LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

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

3574d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b43e8724d67bc227ceeec152478277b62bd2c9a470999e5635a7175e9139382f?d=identicon)[altayalp](/maintainers/altayalp)

---

Top Contributors

[![altayalp](https://avatars.githubusercontent.com/u/3314135?v=4)](https://github.com/altayalp "altayalp (34 commits)")[![eduardojansen](https://avatars.githubusercontent.com/u/993846?v=4)](https://github.com/eduardojansen "eduardojansen (1 commits)")[![emorinaj](https://avatars.githubusercontent.com/u/34061524?v=4)](https://github.com/emorinaj "emorinaj (1 commits)")[![smeghead](https://avatars.githubusercontent.com/u/112476?v=4)](https://github.com/smeghead "smeghead (1 commits)")

---

Tags

ftpsshsftpftp-clientssh-ftpphp ftp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/uri

URI manipulation library

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

Common tools for parsing and resolving RFC3987/RFC3986 URI

536204.9M23](/packages/league-uri-interfaces)[dg/ftp-php

Easy-to-use library for accessing FTP servers

201701.6k3](/packages/dg-ftp-php)[banago/bridge

A PHP class to transfer data using different protocols (sftp, ftp, http, etc). Utilizes PHPs ssh2, ftp and curl functions if available.

2115.1k2](/packages/banago-bridge)[lazzard/php-ftp-client

This library provides helper classes and methods to manage your FTP files in an OOP way.

93213.2k](/packages/lazzard-php-ftp-client)

PHPackages © 2026

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