tofex/curl-ftp

Tofex Curl FTP

1.0.3 2022-04-22 06:13 UTC

This package is auto-updated.

Last update: 2024-09-09 19:59:30 UTC


README

Tofex Curl FTP 提供了一个基于 Curl 的客户端。

安装

$ composer require tofex/curl-ftp

许可证

Tofex Curl FTP 在 MIT 许可证下发布 - 详细信息请参阅 LICENSE 文件。

用法

创建连接

$ftp = new Client();
$ftp->open([
    'host' => 'ftp.example.com',
    'user' => 'username',
    'password' => 'password',
    'port' => 990,
    'ssl' => true,
    'passive' => true,
    'timeout' => 30
]);

或者,您也可以使用 connect() 方法创建连接

$ftp->connect($hostName, $port, $userName, $password, $useSsl, $usePassiveMode, $timeout);

列出文件

$files = $ftp->ls();

print_r($files);

产生

Array
(
    [0] => Array
        (
            [text] => file_1.zip
            [id] => /file_1.zip
        )

    [1] => Array
        (
            [text] => file_2.zip
            [id] => /file_2.zip
        )
)

设置/更改当前目录

$ftp->cd('directory/subdirectory');

读取文件内容

$contents = $ftp->read('path/to/file.zip');

写入文件

$contents = 'file contents';
$ftp->write('path/to/file.txt', $contents);

删除文件/目录

$ftp->rm('path/to/file.txt');

捕获错误

所有异常都以标准的 Exception 类抛出,其消息格式如下

Could not handle content in path: {path} ({cURL error number})