Yii 2.0: yii2-gftp

GFtp is a FTP extension for YII 2 Framework
1 follower

GFtp

GFtp is a FTP extension for YII 2 Framework.

It contains 2 main component :

  • \gftp\FtpComponent : A Yii component used to manage FTP connection and navigation (encapsulates PHP ftp method).
  • \gftp\FtpWidget : A widget which can be used to display FTP folder content and allow FTP server browsing.

It supports FTP protocol and FTP over SSL protocol

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist hguenot/yii2-gftp "*"

or add

"hguenot/yii2-gftp": "*"

to the require section of your composer.json file.

Usage

Here is a basic usage of GFtp extension.

  • Create an FTP application component (in your Web config file)
return [
    // [...]
    'components'=>[
        // [...]
        'ftp' => [
            'class' => '\gftp\FtpComponent',
            'connectionString' => 'ftp://user:pass@host:21',
            'timeout' => 120,
            'passive' => false
        ]
    ],
    // [...]
];
  • You can user either a connection string where protocol could be ftp or ftps or directly set protocol, user, pass, host and port properties :
return [
    // [...]
    'components'=>[
        // [...]
        'ftp' => [
            'class' => '\gftp\FtpComponent',
            'protocol' => \gftp\FtpProtocol::FTPS,
            'user' => 'me@somewhere.otrb',
            'pass' => 'PassW0rd',
            'host' => 'ftp.somewhere.otrb',
            'port' => 2121,
            'timeout' => 120,
            'passive' => false
        ]
    ],
    // [...]
];
  • Use component
$files = $gftp->ls();
$gftp->chdir('images');
  • Display ftp content in a Widget :
use gftp\FtpWidget;
echo FtpWidget::widget();
  • If no FTP(S) connection is passed to the widget, it needs an application component named 'ftp'. But you can pass an FtpComponent directly :
use \gftp\FtpWidget;
echo FtpWidget::widget([
    'ftp' => \Yii::$app->get('otrb')
]);

or

use \gftp\FtpWidget;
use \gftp\FtpComponent;
 
echo FtpWidget::widget([
    'ftp' => new FtpComponent([
            'protocol' => \gftp\FtpProtocol::FTPS,
            'user' => 'me@somewhere.otrb',
            'pass' => 'PassW0rd',
            'host' => 'ftp.somewhere.otrb',
            'port' => 2121,
            'timeout' => 120,
            'passive' => false
    ]);
]);

Resources

...external resources for this extension...

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet