#FtpBundle
A Symfony2 Bundle to wrap the PHP ftp extension functionality in a more "classy" way.
##Installation
Add the following entries to the deps in the root of your project file:
[IjankiFtpBundle]
git=git://github.com/iJanki/FtpBundle.git
target=bundles/Ijanki/Bundle/FtpBundle
Now, run the vendors script to download the bundle:
$ php bin/vendors install
Then you need to add the Ijanki namespace to your autoloader:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Ijanki' => __DIR__.'/../vendor/bundles',
));
Add the following dependency to your composer.json file:
"require": {
# ..
"ijanki/ftp-bundle": "*"
# ..
}
Finally, enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Ijanki\Bundle\FtpBundle\IjankiFtpBundle(),
);
}
<?php
use Ijanki\Bundle\FtpBundle\Exception\FtpException;
public function indexAction()
{
//...
try {
$ftp = $this->container->get('ijanki_ftp');
$ftp->connect($host);
$ftp->login($username, $password);
$ftp->put($destination_file, $source_file, FTP_BINARY);
} catch (FtpException $e) {
echo 'Error: ', $e->getMessage();
}
//...
}
All php ftp functions are wrapped in Ftp object:
For example:
ftp_mkdir becomes $ftp->mkdir or
ftp_put becomes $ftp->put
with the same arguments except the first one (resource $ftp_stream).
Check Ftp.php for other added methods.
Inspired by https://github.com/dg/ftp-php