This is a Symfony2 bundle to wrap the FTP Component
composer.json
{
"require": {
"touki/ftp-bundle": "dev-master"
}
}Then run
$ composer install touki/ftp-bundleThen you must add the bundle in your AppKernel.php
<?php
class AppKernel extends Kernel
{
public function registerBundles()
{
return array(
// ...
new Touki\Bundle\FTPBundle\ToukiFTPBundle()
);
}
}
?>The default configuration is as follows
touki_ftp:
host: localhost # Remote server name
username: anonymous # Username to connect with
password: guest # Password to connect with
port: 21 # Port to connect to
secured: false # Whether to connect with SSL or notFor the standard usage of the component, please read the documentation
<?php
$container->get('ftp.connection');
?>Holds the connection to the server. It opens it by default.
<?php
$container->get('ftp.wrapper');
?>The simple FTP wrapper.
<?php
$container->get('ftp.manager');
?>The filesystem manager
<?php
$container->get('ftp');
?>The main FTP Class
To add a custom downloader, you need to create a downloader which implements the interfaces as follows
<?php
namespace Acme\FooBundle\Downloader;
use Touki\FTP\DownloaderInterface;
use Touki\FTP\DownloaderVotableInterface;
use Touki\FTP\Model\Filesystem;
class MyDownloader implements DownloaderInterface, DownloaderVotableInterface
{
/**
* {@inheritDoc}
*/
public function vote($local, Filesystem $remote, array $options = array())
{
// Return a boolean based on arguments given to check if the downloader is compatible
}
/**
* {@inheritDoc}
*/
public function download($local, Filesystem $remote, array $options = array())
{
// Process the download
}
}
?>Then in your services.yml, create a new service which adds the ftp.downloader tag
services:
acme_foo.mydownloader:
class: Acme\FooBundle\Downloader\MyDownloader
tags:
- { name: ftp.downloader, prepend: false } # Set prepend to true to prepend the downloaderTo add a custom uploader, you need to create a uploader which implements the interfaces as follows
<?php
namespace Acme\FooBundle\Uploader;
use Touki\FTP\UploaderInterface;
use Touki\FTP\UploaderVotableInterface;
use Touki\FTP\Model\Filesystem;
class MyUploader implements UploaderInterface, UploaderVotableInterface
{
/**
* {@inheritDoc}
*/
public function vote(Filesystem $remote, $local, array $options = array())
{
// Return a boolean based on arguments given to check if the uploader is compatible
}
/**
* {@inheritDoc}
*/
public function upload(Filesystem $remote, $local, array $options = array())
{
// Process the upload
}
}
?>Then in your services.yml, create a new service which adds the ftp.uploader tag
services:
acme_foo.myuploader:
class: Acme\FooBundle\Uploader\MyUploader
tags:
- { name: ftp.uploader, prepend: false } # Set prepend to true to prepend the uploader