yii2mod/yii2-ftp
Composer 安装命令:
composer require yii2mod/yii2-ftp
包简介
A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.
README 文档
README
FTP Client for Yii 2
yii2-ftp is a fork of Nicolab/php-ftp-client v1.2.0
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii2mod/yii2-ftp "*"
or add
"yii2mod/yii2-ftp": "*"
to the require section of your composer.json.
Getting Started
Connect to a server FTP :
$ftp = new \yii2mod\ftp\FtpClient(); $host = 'ftp.example.com'; $ftp->connect($host); $ftp->login($login, $password);
OR
Connect to a server FTP via SSL (on port 22 or other port) :
$ftp = new \yii2mod\ftp\FtpClient(); $host = 'ftp.example.com'; $ftp->connect($host, true, 22); $ftp->login($login, $password);
Note: The connection is implicitly closed at the end of script execution (when the object is destroyed). Therefore it is unnecessary to call $ftp->close(), except for an explicit re-connection.
Usage
Upload all files and all directories is easy :
// upload with the BINARY mode $ftp->putAll($source_directory, $target_directory); // Is equal to $ftp->putAll($source_directory, $target_directory, FTP_BINARY); // or upload with the ASCII mode $ftp->putAll($source_directory, $target_directory, FTP_ASCII);
Note : FTP_ASCII and FTP_BINARY are predefined PHP internal constants.
Get a directory size :
// size of the current directory $size = $ftp->dirSize(); // size of a given directory $size = $ftp->dirSize('/path/of/directory');
Count the items in a directory :
// count in the current directory $total = $ftp->count(); // count in a given directory $total = $ftp->count('/path/of/directory'); // count only the "files" in the current directory $total_file = $ftp->count('.', 'file'); // count only the "files" in a given directory $total_file = $ftp->count('/path/of/directory', 'file'); // count only the "directories" in a given directory $total_dir = $ftp->count('/path/of/directory', 'directory'); // count only the "symbolic links" in a given directory $total_link = $ftp->count('/path/of/directory', 'link');
Detailed list of all files and directories :
// scan the current directory and returns the details of each item $items = $ftp->scanDir(); // scan the current directory (recursive) and returns the details of each item var_dump($ftp->scanDir('.', true));
Result:
'directory#www' =>
array (size=10)
'permissions' => string 'drwx---r-x' (length=10)
'number' => string '3' (length=1)
'owner' => string '32385' (length=5)
'group' => string 'users' (length=5)
'size' => string '5' (length=1)
'month' => string 'Nov' (length=3)
'day' => string '24' (length=2)
'time' => string '17:25' (length=5)
'name' => string 'www' (length=3)
'type' => string 'directory' (length=9)
'link#www/index.html' =>
array (size=11)
'permissions' => string 'lrwxrwxrwx' (length=10)
'number' => string '1' (length=1)
'owner' => string '0' (length=1)
'group' => string 'users' (length=5)
'size' => string '38' (length=2)
'month' => string 'Nov' (length=3)
'day' => string '16' (length=2)
'time' => string '14:57' (length=5)
'name' => string 'index.html' (length=10)
'type' => string 'link' (length=4)
'target' => string '/var/www/shared/index.html' (length=26)
'file#www/README' =>
array (size=10)
'permissions' => string '-rw----r--' (length=10)
'number' => string '1' (length=1)
'owner' => string '32385' (length=5)
'group' => string 'users' (length=5)
'size' => string '0' (length=1)
'month' => string 'Nov' (length=3)
'day' => string '24' (length=2)
'time' => string '17:25' (length=5)
'name' => string 'README' (length=6)
'type' => string 'file' (length=4)
All FTP PHP functions are supported and some improved :
// Requests execution of a command on the FTP server $ftp->exec($command); // Turns passive mode on or off $ftp->pasv(true); // Set permissions on a file via FTP $ftp->chmod('0777', 'file.php'); // Removes a directory $ftp->rmdir('path/of/directory/to/remove'); // Removes a directory (recursive) $ftp->rmdir('path/of/directory/to/remove', true); // Creates a directory $ftp->mkdir('path/of/directory/to/create'); // Creates a directory (recursive), // creates automaticaly the sub directory if not exist $ftp->mkdir('path/of/directory/to/create', true); // and more ...
Get the help information of remote FTP server :
var_dump($ftp->help());
Result :
array (size=6)
0 => string '214-The following SITE commands are recognized' (length=46)
1 => string ' ALIAS' (length=6)
2 => string ' CHMOD' (length=6)
3 => string ' IDLE' (length=5)
4 => string ' UTIME' (length=6)
5 => string '214 Pure-FTPd - http://pureftpd.org/' (length=36)
Note : The result depend of FTP server.
Support us
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
yii2mod/yii2-ftp 适用场景与选型建议
yii2mod/yii2-ftp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 451.21k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2014 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 「extension」 「server」 「helper」 「sftp」 「ftp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yii2mod/yii2-ftp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yii2mod/yii2-ftp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yii2mod/yii2-ftp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 451.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 27
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-10