Yii2-Gftp (Remote connection to FTP server)

Yii2-Gftp (Remote connection to FTP server)

hguenot/yii2-gftp

Install Demo

Он поддерживает протокол FTP и FTP через SSL протокол.

Publication time: Friday, July 3, 2015 (4 years ago)

Created by: Семенов Александр Сергеевич

Category: Other

Current version: 2.2.0
Feb 19, 2018, 8:33:29 AM (a year ago)

Packagist: hguenot/yii2-gftp

: https://github.com/hguenot/yii2-gftp

: 28017 (Per month: 838)

Type of: Компонент


Он поддерживает протокол FTP и FTP через SSL протокол.

В этом решение есть виджет и компонент.

Latest Stable Version Total Downloads License

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. SFTP support is provider by Yii2-gsftp extension.

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' => [
            'connectionString' => 'ftp://user:pass@host:21',
            'driverOptions' =>  [
                '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',
            'driverOptions' =>  [
                'class' => '\gftp\drivers\SftpProtocol',
                'user' => 'me@somewhere.otrb',
                'pass' => 'PassW0rd',
                'host' => 'ftp.somewhere.otrb',
                'port' => 2121,
                'timeout' => 120,
                'passive' => false
            ]
        ]
    ],
    // [...]
];
  • Use component
$files = $gftp->ls();
$gftp->chdir('images');

More complete example :

public function actionExample() { 
    $remote_file = '/data/users.txt'; 
    $local_file = '/tmp/users.load'; 
    $mode = 'FTP_ASCII'; 
    $asynchronous = false; 
    $file = Yii::$app->ftp->get($remote_file, $local_file, $mode, $asynchronous); 
    // [...]
} 
  • 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([
            'driverOptions' =>  [
                'class' => '\gftp\drivers\SftpProtocol',
                'user' => 'me@somewhere.otrb',
                'pass' => 'PassW0rd',
                'host' => 'ftp.somewhere.otrb',
                'port' => 2121,
                'timeout' => 120,
                'passive' => false
            ]
    ]);
]);

All Comments (0)
No Comments

dev-master — Jun 24, 2019, 3:26:18 PM (2 months ago)

2.2.0 — Feb 19, 2018, 8:33:29 AM (a year ago)

2.1.3 — May 9, 2016, 3:36:01 PM (3 years ago)

V2.1.2 — Dec 11, 2015, 4:56:57 PM (3 years ago)

V2.1.1 — Nov 2, 2015, 11:54:40 PM (3 years ago)

2.1 — Aug 3, 2015, 10:48:45 AM (4 years ago)

2.0.1 — Jul 15, 2015, 11:04:50 PM (4 years ago)

2.0 — Jun 19, 2015, 10:32:30 PM (4 years ago)

1.0 — Jun 14, 2015, 9:10:54 AM (4 years ago)

Стандартная установка:

Добавьте composer.json файл вашего проекта:

"hguenot/yii2-gftp": "*"

Запустите обновление зависимостей


Читать про обнолвение SkeekS CMS