定制 hguenot/yii2-gftp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hguenot/yii2-gftp

最新稳定版本:3.0.3

Composer 安装命令:

composer require hguenot/yii2-gftp

包简介

Ftp is a FTP extension for [YII 2 Framework](http://www.yiiframework.com).

README 文档

README

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 ] ]); ]);

统计信息

  • 总下载量: 128.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 3
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 4
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固