projectsaturnstudios/laravel-x-fer
Composer 安装命令:
composer require projectsaturnstudios/laravel-x-fer
包简介
Transfer files between servers using SFTP or AWS S3
README 文档
README
A simple Laravel package that lets you build streaming file transfers between two defined Laravel filesystem drivers using a factory pattern for one-line transfers. Perfect for ETL processes, data migrations, and cross-server file operations.
Requirements
- Laravel 11 or greater
- PHP 8.2 or greater
Installation
You can install the package via composer:
composer require projectsaturnstudios/laravel-x-fer
After installation, you can optionally publish the configuration file and migration:
php artisan vendor:publish --tag=xfer-config php artisan vendor:publish --tag=xfer-migrations
Run the migrations if you plan to use the logging features:
php artisan migrate
Configuration
After publishing the config file, you can modify config/file-transfers.php to customize the batch processing behavior:
return [ /* |-------------------------------------------------------------------------- | File Transfer Batch Driver |-------------------------------------------------------------------------- | | This option controls the batch driver that will be used to process file | transfers. You may set this to any of the drivers provided by the | package or create your own custom driver that implements the | ProjectSaturnStudios\Xfer\Contracts\BatchDriver interface. | | Supported: "sync", "bus", "concurrency", "chain" | */ 'batch_processing' => [ 'driver' => env('XFER_BATCH_DRIVER', 'sync'), 'drivers' => [ 'sync' => ProjectSaturnStudios\Xfer\Drivers\BatchProcessing\SyncBatchDriver::class, 'bus' => ProjectSaturnStudios\Xfer\Drivers\BatchProcessing\BusBatchDriver::class, 'chain' => ProjectSaturnStudios\Xfer\Drivers\BatchProcessing\ChainBatchDriver::class, 'concurrency' => ProjectSaturnStudios\Xfer\Drivers\BatchProcessing\ConcurrencyBatchDriver::class, ], ], 'folder_associations' => [ 'production' => [ 'sftp' => 'production', 's3-processed' => 'production/processed', ], 'staging' => [ 'sftp' => 'staging', 's3-processed' => 'staging/processed', ], 'archive' => [ 'sftp' => 'archive', 's3-processed' => 'archive/processed', ], ], ];
Usage
One-off Transfer
Perform a simple file transfer between two storage disks:
use ProjectSaturnStudios\Xfer\Support\Facades\CopyFile; $copied = CopyFile::from('sftp', 'folder', 'doc.csv') ->to('local', 'folder', 'saved-doc.csv') ->transfer();
Transfer with Logging
Add event sourcing and audit trails to your transfers:
$results = CopyFile::from('sftp', 'folder', 'doc.csv') ->to('local', 'folder', 'saved-doc.csv') ->withLogging() ->transfer();
Transfer Multiple Files
Use batch processing for multiple file transfers:
use ProjectSaturnStudios\Xfer\Support\Facades\BatchTransfer; use ProjectSaturnStudios\Xfer\DTO\Transfers\FileObject; $batch = BatchTransfer::driver('concurrency'); foreach($transfers as $transfer) { $batch = $batch->addTransfer($transfer['source'], $transfer['destination']); } $results = $batch->dispatch();
Transfer Multiple Files with Logging
Combine batch processing with logging:
use ProjectSaturnStudios\Xfer\Support\Facades\BatchTransfer; use ProjectSaturnStudios\Xfer\DTO\Transfers\FileObject; $batch = BatchTransfer::driver('concurrency'); foreach($transfers as $transfer) { $batch = $batch->addTransfer($transfer['source'], $transfer['destination']); } $results = $batch->withLogging()->dispatch();
Batch Processing Drivers
Laravel X-Fer provides four built-in batch processing drivers:
1. Sync Driver
Processes transfers synchronously (one after another). Best for small batches or when order matters.
2. Bus Driver
Uses Laravel's job bus to queue transfers. Ideal for background processing and decoupling from the main request.
3. Chain Driver
Chains transfers using Laravel's job chaining. Useful when transfers need to happen in sequence.
4. Concurrency Driver
Processes transfers concurrently using Laravel 11's new concurrency features. Perfect for large batches where parallel processing improves performance.
Custom Drivers
You can create custom batch drivers by extending the base driver class:
use ProjectSaturnStudios\Xfer\Drivers\BatchProcessing\BatchProcessingDriver; class CustomBatchDriver extends BatchProcessingDriver { public function process(array $items, bool $use_logging = false): array|bool { // Your custom batch processing logic foreach ($items as $item) { // Process each transfer } return $results; } }
Register your custom driver in your service provider:
use ProjectSaturnStudios\Xfer\Support\Facades\BatchManager; BatchManager::extend('custom', function ($app) { return new CustomBatchDriver(); });
Alternatively, after publishing the config file, you can replace any of the built-in drivers in the batch_processing.drivers array:
'drivers' => [ 'sync' => \App\Drivers\MyCustomSyncDriver::class, // ... other drivers ],
API Reference
CopyFile Facade
from(string $disk, string $folder, string $path): static
Define the source file location.
to(string $disk, string $folder, string $path): static
Define the destination file location.
withLogging(bool $enabled = true): static
Enable event sourcing and logging for the transfer.
transfer(): bool|TransferResult
Execute the file transfer. Returns bool for simple transfers, TransferResult for logged transfers.
BatchTransfer Facade
driver(?string $name = null): static
Set the batch processing driver.
addTransfer(FileObject $source, FileObject $destination): static
Add a transfer to the batch.
addTransfers(array $transfers): static
Add multiple transfers to the batch.
withLogging(): static
Enable logging for all transfers in the batch.
dispatch(): array|bool
Execute all transfers in the batch.
Testing
composer test
Credits
projectsaturnstudios/laravel-x-fer 适用场景与选型建议
projectsaturnstudios/laravel-x-fer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 259 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「s3」 「sftp」 「laravel」 「file-transfer」 「xfer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 projectsaturnstudios/laravel-x-fer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 projectsaturnstudios/laravel-x-fer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 projectsaturnstudios/laravel-x-fer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
A simple database backup manager for Symfony2 with support for S3, Rackspace, Dropbox, FTP, SFTP.
统计信息
- 总下载量: 259
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-08