achrafsoltani / sftp-service-provider
Silex 的 SFTP 服务提供程序
v2.0.0
2016-06-15 12:35 UTC
Requires
- php: >=5.3.0
- ext-ssh2: *
- monolog/monolog: *
- silex/silex: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 17:42:48 UTC
README
为 Silex 提供简单的 SFTP 包装器
特性
- 易于设置。
- 文件:列表、上传、下载、重命名、删除。
- 文件夹:列表、创建、重命名、删除。
要求
- PHP 5.3+
- ext-ssh2
- monolog/monolog(通过 MonologServiceProvider)
依赖关系
// Installing php-ssh2 $ sudo apt-get install libssh2-php // checking if all is good $ php -m |grep ssh2
安装
$ composer require achrafsoltani/sftp-service-provider
设置
require_once __DIR__.'/vendor/autoload.php';
use Silex\Application;
use AchrafSoltani\Provider\SftpServiceProvider;
use Silex\Provider\MonologServiceProvider;
$app = new Application();
// Monolog
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => __DIR__.'/logs/development.log',
));
// SFTP
$app->register(new SftpServiceProvider(), array(
'sftp.options' => array(
'hostname' => 'domain.tld', // or IP address
'username' => 'root',
'password' => 'your_ssh_password',
'port' => '22' // optional
)
));
// Usage
$app->run();
使用方法
- 示例 1:列出目录中的文件
$dirs = $app['sftp']->list_files('/home/user/');
var_dump($dirs);
- 示例 2:下载文件
$app['sftp']->download('/home/user/source_file.ext', '/home/user/path/to/destination/downloaded.ext');