tomedio/php-ftp-client
Composer 安装命令:
composer require tomedio/php-ftp-client
包简介
A modern FTP and SSL-FTP client for PHP, offering easy-to-use helpers for managing remote files.
README 文档
README
A modern FTP and SSL-FTP client for PHP, offering easy-to-use helpers for managing remote files.
Note: This library requires PHP >=8.1.
Installation
To get started with PHP FTP Client in your project, you can install it via Composer:
composer require tomedio/php-ftp-client
After installation, you can use the library in your PHP project to connect to an FTP server and perform various operations.
Getting Started
Connect to an FTP server:
$ftp = new \FtpClient\FtpClient(); $ftp->connect($host); $ftp->login($login, $password);
OR
Connect to an FTP server via SSL (on port 990 or another port):
$ftp = new \FtpClient\FtpClient(); $ftp->connect($host, true, 990); $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 directories:
// Upload with the BINARY mode $ftp->putAll($sourceDirectory, $targetDirectory); // Is equal to $ftp->putAll($sourceDirectory, $targetDirectory, FTP_BINARY); // Or upload with the ASCII mode $ftp->putAll($sourceDirectory, $targetDirectory, 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->countItems(); // Or alias $total = $ftp->count();
Detailed list of all files and directories in a directory:
$items = $ftp->scanDir(); // scan the current directory (recursive) and returns the details of each item var_dump($ftp->scanDir('.', true));
Results:
'directory#public' =>
array (size=10)
'permissions' => string 'drwxr-xr-x' (length=10)
'number' => string '2' (length=1)
'owner' => string '1000' (length=4)
'group' => string 'staff' (length=5)
'size' => string '4096' (length=4)
'month' => string 'Dec' (length=3)
'day' => string '12' (length=2)
'time' => string '10:15' (length=5)
'name' => string 'public' (length=6)
'type' => string 'directory' (length=9)
'link#public/logo.png' =>
array (size=11)
'permissions' => string 'lrwxrwxrwx' (length=10)
'number' => string '1' (length=1)
'owner' => string '1000' (length=4)
'group' => string 'staff' (length=5)
'size' => string '20' (length=2)
'month' => string 'Dec' (length=3)
'day' => string '10' (length=2)
'time' => string '09:30' (length=5)
'name' => string 'logo.png' (length=8)
'type' => string 'link' (length=4)
'target' => string '/var/www/shared/logo.png' (length=24)
'file#public/index.php' =>
array (size=10)
'permissions' => string '-rw-r--r--' (length=10)
'number' => string '1' (length=1)
'owner' => string '1000' (length=4)
'group' => string 'staff' (length=5)
'size' => string '1234' (length=4)
'month' => string 'Dec' (length=3)
'day' => string '12' (length=2)
'time' => string '10:15' (length=5)
'name' => string 'index.php' (length=9)
'type' => string 'file' (length=4)
Upload a file to the FTP server:
$ftp->put($localFile, $remoteFile);
Download a file from the FTP server:
$ftp->get($remoteFile, $localFile);
Delete a file from the FTP server:
$ftp->delete($file);
Delete a directory from the FTP server:
$ftp->deleteDir($directory);
Create a directory on the FTP server:
$ftp->makeDir($directory);
Rename a file or directory on the FTP server:
$ftp->rename($oldName, $newName);
Change the permissions of a file or directory on the FTP server:
$ftp->chmod($mode, $file);
Change the owner of a file or directory on the FTP server:
$ftp->chown($owner, $file);
Change the group of a file or directory on the FTP server:
$ftp->chgrp($group, $file);
Get the last modified time of a file or directory on the FTP server:
$ftp->mdtm($file);
Get the size of a file on the FTP server:
$ftp->size($file);
Get the system type of the FTP server:
$ftp->systype();
Get the current working directory on the FTP server:
$ftp->pwd();
Change the current working directory on the FTP server:
$ftp->chdir($directory);
List the contents of the current directory on the FTP server:
$ftp->nlist();
List the contents of a directory on the FTP server:
$ftp->nlist($directory);
Error Handling
The library throws exceptions when an error occurs. You can catch exceptions to handle errors in your application:
try { // Code that may throw an exception } catch (\FtpClient\FtpException $e) { // Handle the exception echo 'An error occurred: ' . $e->getMessage(); }
License
PHP FTP Client is open-source software licensed under the MIT license.
tomedio/php-ftp-client 适用场景与选型建议
tomedio/php-ftp-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 「library」 「server」 「helper」 「sftp」 「ftp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomedio/php-ftp-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomedio/php-ftp-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomedio/php-ftp-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
Inbox pattern process implementation for your Laravel Applications
Laravel Media Popup to upload/view the files
A jQuery augmented PHP library for creating and validating HTML forms
PMVC Plugin for File information
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-09