coercive/sftp

Coercive SFTP

0.0.0 2023-04-24 17:04 UTC

This package is auto-updated.

Last update: 2024-09-24 20:02:48 UTC


README

PHP 的 SFTP 工具

获取

composer require coercive/sftp

依赖项

此包使用 ext-ssh2 : 手册

用法

连接到 FTP

use Coercive\Utility\SFTP\SFTP;

$SFtp = new SFTP('127.0 0.1', 22);
$SFtp->login('BestUser', 'BestPassword');
$SFtp->connect();

断开连接

$SFtp->disconnect();

创建目录

$SFtp->mkdir('/example/dir/test');

列出目录和文件

$data = $SFtp->list('/example/dir/test');

上传文件

$SFtp->upload('/README.md', '/example/dir/test/test.md');

下载文件

$SFtp->download('/example/dir/test/test.md', '/test/dowloaded_file.md');

下载文件:带有自动临时文件名和前缀

$SFtp->setTmpPrefix('_test_tmp_prefix_');
$SFtp->download('/example/dir/test/test.md', $filepath);

# do something with your file
rename($filepath, '/test/dowloaded_file.md');

文件大小

$integer = $SFtp->filesize('/example/dir/test/test.md');

读取文件

$data = $SFtp->read('/example/dir/test/test.md');

写入文件

$SFtp->write('/example/dir/test/test.md', "# Hello World !\n");

删除文件

$SFtp->delete('/example/dir/test/test.md');