Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolab committed Jul 11, 2014
0 parents commit 499116d
Show file tree
Hide file tree
Showing 12 changed files with 1,384 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
/vendor
composer.phar
composer.lock
.DS_Store
Thumbs.db
/.Trash-1000
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2014 Nicolas Tallefourtane dev@nicolab.net

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
209 changes: 209 additions & 0 deletions README.md
@@ -0,0 +1,209 @@
# 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.


## Install

* Use composer: `composer install nicolab/php-ftp-client`

* Or use GIT clone command: `git clone git@github.com:Nicolab/php-ftp-client.git`

* Or download the library, configure your autoloader or include the 3 files of `nicolab/php-ftp-client/src/FtpClient` directory.


## Getting Started

Connect to a server FTP :

```php
$ftp = new \FtpClient\FtpClient();
$ftp->connect($host);
$ftp->login($login, $password);
```

OR

Connect to a server FTP via SSL (on port 22 or other port) :

```php
$ftp = new \FtpClient\FtpClient();
$ftp->connect($host, true, 22);
$ftp->login($login, $password);
```


### Usage

Upload all files and all directories is easy :

```php
// upload with the ASCII mode
$ftp->putAll($source_directory, $target_directory);

// Is equal to
$ftp->putAll($source_directory, $target_directory, FTP_ASCII);

// or upload with the binary mode
$ftp->putAll($source_directory, $target_directory, FTP_BINARY);

```

*Note : FTP_ASCII and FTP_BINARY is the predefined PHP internal constant.*

Get the a directory size :

```php

// size of the current directory
$size = $ftp->dirSize();

// size of a given directory
$size = $ftp->dirSize('/path/of/directory');

```

Count the items in a directory :

```php

// count in the current directory
$total = $ftp->count();

// count in a given directory
$total = $ftp->count('/path/of/directory');

// count only the "files" in the current directory
$total_file = $ftp->count('.', 'file');

// count only the "files" in a given directory
$total_file = $ftp->count('/path/of/directory', 'file');

// count only the "directories" in a given directory
$total_dir = $ftp->count('/path/of/directory', 'directory');

// count only the "symbolic links" in a given directory
$total_link = $ftp->count('/path/of/directory', 'link');

```

List detailed of all files and directories :

```php
// scan the current directory and returns the details of each item
$items = $ftp->scanDir();

// scan the current directory (recursive) and returns the details of each item
var_dump($ftp->scanDir('.', true));
```

Result:

'directory#www' =>
array (size=10)
'permissions' => string 'drwx---r-x' (length=10)
'number' => string '3' (length=1)
'owner' => string '32385' (length=5)
'group' => string 'users' (length=5)
'size' => string '5' (length=1)
'month' => string 'Nov' (length=3)
'day' => string '24' (length=2)
'time' => string '17:25' (length=5)
'name' => string 'www' (length=3)
'type' => string 'directory' (length=9)

'link#www/index.html' =>
array (size=11)
'permissions' => string 'lrwxrwxrwx' (length=10)
'number' => string '1' (length=1)
'owner' => string '0' (length=1)
'group' => string 'users' (length=5)
'size' => string '38' (length=2)
'month' => string 'Nov' (length=3)
'day' => string '16' (length=2)
'time' => string '14:57' (length=5)
'name' => string 'index.html' (length=10)
'type' => string 'link' (length=4)
'target' => string '/var/www/shared/index.html' (length=26)

'file#www/README' =>
array (size=10)
'permissions' => string '-rw----r--' (length=10)
'number' => string '1' (length=1)
'owner' => string '32385' (length=5)
'group' => string 'users' (length=5)
'size' => string '0' (length=1)
'month' => string 'Nov' (length=3)
'day' => string '24' (length=2)
'time' => string '17:25' (length=5)
'name' => string 'README' (length=6)
'type' => string 'file' (length=4)


All FTP PHP functions are supported and some improved :

```php

// Requests execution of a command on the FTP server
$ftp->exec($command);

// Turns passive mode on or off
$ftp->pasv(true);

// Set permissions on a file via FTP
$ftp->chmod('0777', 'file.php');

// Removes a directory
$ftp->rmdir('path/of/directory/to/remove');

// Removes a directory (recursive)
$ftp->rmdir('path/of/directory/to/remove', true);

// Creates a directory
$ftp->mkdir('path/of/directory/to/create');

// Creates a directory (recursive),
// creates automaticaly the sub directory if not exist
$ftp->mkdir('path/of/directory/to/create', true);

// and more ...

```

Get the help information of the remote FTP server :

```php
var_dump($ftp->help());
```

Result :

array (size=6)
0 => string '214-The following SITE commands are recognized' (length=46)
1 => string ' ALIAS' (length=6)
2 => string ' CHMOD' (length=6)
3 => string ' IDLE' (length=5)
4 => string ' UTIME' (length=6)
5 => string '214 Pure-FTPd - http://pureftpd.org/' (length=36)


_Note : The result depend of the FTP server._


## Testing

Tested with "atoum" unit testing framework.


## License

[MIT](https://github.com/Nicolab/php-ftp-client/blob/master/LICENSE)


## Author

| [![Nicolas Tallefourtane - Nicolab.net](http://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](http://nicolab.net) |
|---|
| [Nicolas Talle](http://nicolab.net) |
| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |
22 changes: 22 additions & 0 deletions composer.json
@@ -0,0 +1,22 @@
{
"name": "nicolab/php-ftp-client",
"type": "library",
"description": "A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.",
"license": "MIT",
"keywords": ["ftp", "sftp", "ssl-ftp", "ssl", "file", "server", "lib", "helper"],
"homepage": "https://github.com/Nicolab/php-ftp-client",

"authors" : [
{
"name" : "Nicolas Tallefourtane",
"email" : "dev@nicolab.net",
"homepage" : "http://nicolab.net"
}
],
"require": {
"php": ">=5.4"
},
"autoload": {
"psr-0": {"FtpClient": "src/"}
}
}

0 comments on commit 499116d

Please sign in to comment.