osw3/php-cloud-manager

提供云连接和文件操作工具。

0.0.5 2024-09-30 01:13 UTC

This package is auto-updated.

Last update: 2024-09-30 01:14:16 UTC


README

提供云连接和文件操作工具。

如何安装

composer require osw3/php-cloud-manager

支持的服务

如何使用

创建新的连接

准备DSN

$dsn = "{$driver}://{$user}:{$pass}@{$host}";

客户端实例

use OSW3\CloudManager\Client;
$client = new Client($dsn);
不要自动连接
$client = new Client($dsn, false);
$client->connect();

DSN信息

  • dsn(): DsnService

    到DsnService的桥梁。

    $client->dsn()->getDriver(); // ftp
  • getDriver(): ?string

    $client->dsn()->getDriver(); // ftp
  • getHost(): ?string

    $client->dsn()->getHost(); // site.com
  • getUser(): ?string

    $client->dsn()->getUser(); // user
  • getPass(): ?string

    $client->dsn()->getPass(); // pass
  • getAuth(): ?int

    获取认证模式

    $client->dsn()->getAuth();
  • getToken(): ?int

    $client->dsn()->getToken();
  • getPort(): ?int

    $client->dsn()->getPort(); // 21
  • get(): ?string

    获取DSN字符串

    $client->dsn()->get(); // ftp://user:pass@site.com";

驱动器语句

  • connect(): bool

    执行驱动器连接并返回连接状态

    $client->connect();
  • disconnect(): bool

    执行断开连接并返回连接状态

    $client->disconnect();
  • isConnected(): bool

    当驱动器连接时返回 true

    $client->isConnected();

临时目录

  • setTempDirectory(string $directory): static

    设置用于文件操作的本地服务器临时目录。

    $client->setTempDirectory("my/temp/dir");
  • getTempDirectory(): string

    获取用于文件操作的本地服务器临时目录。

    $client->getTempDirectory();

导航

  • location(): string

    返回当前位置(类似于PWD)

    $client->location();
  • navigateTo(string $folder): bool

    将指针设置为特定文件夹。

    $client->navigateTo("/www");
  • parent(): bool

    将指针设置为父文件夹。

    $client->parent();
  • root(): bool

    将指针设置为驱动器的根。

    $client->root();

条目信息

  • infos(?string $path=null, ?string $part=null): array|string

    检索条目信息。如果$part为null,则返回数组。

    $client->infos("/www/my-dir"); // [...]
    $client->infos("/www/my-dir", "type"); // folder
  • isFolder(string $path): bool

    如果$path是文件夹类型,则返回true。

    $client->isFolder("/www/my-dir");
  • isDirectory(string $path): bool

    isFolder的别名

    $client->isDirectory("/www/my-dir");
  • isFile(string $path): bool

    如果$path是文件类型,则返回true。

    $client->isFile("/www/my-dir");
  • isLink(string $path): bool

    如果$path是链接类型,则返回true。

    $client->isLink("/www/my-dir");
  • isBlock(string $path): bool

    如果$path是块类型,则返回true

    $client->isBlock("/www/my-dir");
  • isCharacter(string $path): bool

    如果$path是字符类型,则返回true。

    $client->isCharacter("/www/my-dir");
  • isSocket(string $path): bool

    如果$path是套接字类型,则返回true。

    $client->isSocket("/www/my-dir");
  • isPipe(string $path): bool

    如果$path是管道类型,则返回true。

    $client->isPipe("/www/my-dir");

权限

  • permissions(string $path, ?int $code=null): string|bool

    权限获取器和设置器。如果$code不为null,则设置路径的权限。如果$code为null,则获取权限代码。

    $client->permissions("/www/my-dir", 0777); // true
    $client->permissions("/www/my-dir"); // 0777
  • setPermission(string $path, int $code): bool

    将权限代码设置为路径

    $client->setPermission("/www/my-dir", 0777);
  • getPermission(string $path): string

    从路径中读取权限代码

    $client->getPermission("/www/my-dir"); // 0777

文件夹API

  • browse(?string $directory=null): array

    返回目录内容,类似于Unix PWD命令。如果$directory参数为null,则返回当前指针位置的内容。

    $client->browse("/www/my-dir"); // [...]
  • createFolder(string $directory, int $permissions=0700, bool $navigateTo = true): bool

    创建一个目录,并将指针设置到新位置(如果$navigateTo为true)。

    $client->createFolder("/www/my-dir/my-sub-dir");
  • deleteFolder(?string $directory, bool $recursive=true): bool

    删除目录及其内容。

    $client->deleteFolder("/www/my-dir/my-sub-dir");
  • duplicateFolder(string $source, string $destination): bool

    在客户端复制目录

    $client->duplicateFolder("/www/my-dir", "/www/my-other-dirt");
  • copyFolder(string $source, string $destination): bool

    copyFolder的别名

  • moveFolder(string $source, string $destination, bool $override=false): bool

    移动文件夹(剪切+粘贴)

    $client->moveFolder("C://my-dir", "/www/my-dir");
  • uploadFolder(string $source, string $destination, bool $override=false): bool

    将服务器上的目录发送到远程客户端

    $client->uploadFolder("C://my-dir", "/www/my-dir");
  • downloadFolder(string $source, string $destination, bool $override=false): bool

    从客户端获取目录到服务器

    $client->downloadFolder("/www/my-dir", "C://my-dir");

文件API

  • createFile(string $filename, string $content="", bool $binary=false): bool

    从流创建文件到客户端。

    $client->createFile("/www/my-dir/my-file.txt", "Hi!\This is my file.");
  • deleteFile(?string $filename): bool

    从客户端删除文件。

    $client->deleteFile("/www/my-dir/my-file.txt");
  • duplicateFile(string $source, string $destination): bool

    在客户端复制文件

    $client->duplicateFile("/www/my-dir/my-file.txt", "/www/my-other-dir/my-file.txt");
  • copyFile(string $source, string $destination): bool

    duplicateFile的别名。

  • moveFile(string $source, string $destination, bool $override=false): bool

    移动文件

    $client->moveFile("C://my-dir/my-file.txt", "/www/my-dir/my-file.txt");
  • uploadFile(string $source, string $destination, bool $override=false): bool

    将文件从您的服务器发送到远程客户端

    $client->uploadFile("C://my-dir/my-file.txt", "/www/my-dir/my-file.txt");
  • downloadFile(string $source, string $destination, bool $override=false): bool

    从客户端获取文件到您的服务器

    $client->downloadFile("/www/my-dir/my-file.txt", "C://my-dir/my-file.txt");

文件夹与文件API(前一个API的混合别名)

  • delete(?string $path, bool $recursive=true): bool;

    删除目录或文件

    $client->delete("/www/my-dir/my-file.txt");
    $client->delete("/www/my-dir");
  • duplicate(string $source, string $destination): bool;

    复制目录或文件

    $client->duplicate("/www/my-dir/my-file.txt", "/www/my-sub-dir/my-file.txt");
    $client->duplicate("/www/my-dir", "/www/my-sub-dir");
  • copy(string $source, string $destination): bool;

    duplicate的别名

  • move(string $source, string $destination): bool;

    复制目录或文件并删除$source

    $client->move("/www/my-dir/my-file.txt", "/www/my-sub-dir/my-file.txt");
    $client->move("/www/my-dir", "/www/my-sub-dir");
  • rename(string $source, string $destination): bool;

    move的别名

  • upload(string $source, string $destination, bool $override=false): bool;

    将目录或文件从您的服务器发送到客户端

    $client->upload("C://my-dir", "/www/my-dir");
    $client->upload("C://my-dir/my-file.txt", "/www/my-dir/my-file.txt");
  • download(string $source, string $destination, bool $override=false): bool;

    从客户端获取目录或文件到您的服务器

    $client->download("/www/my-dir", "C://my-dir");
    $client->download("/www/my-dir/my-file.txt", "C://my-dir/my-file.txt");