buuum/ftp

PHP FTP 函数库

v1.0.1 2018-05-14 09:07 UTC

This package is auto-updated.

Last update: 2024-09-17 20:02:36 UTC


README

Packagist license

安装

系统要求

使用 Buuum\Ftp 需要 PHP >= 5.5.0,但推荐使用最新稳定版本的 PHP。

Composer

Buuum\Ftp 在 Packagist 上可用,可以使用 Composer 进行安装

composer require buuum/ftp

手动安装

只要您的自动加载器遵循 PSR-0 或 PSR-4 标准,您就可以使用自己的自动加载器。只需将 src 目录的内容放入您的 vendor 目录。

 初始化

$host = 'my__host';
$username = 'my_username';
$password = 'my_pass';

$connection = new Connection($host, $username, $password);
//$connection = new AnonymousConnection($host);
//$connection = new SSLConnection($host, $username, $password);
try {
    $connection->open();
} catch (\Exception $e) {
    echo $e->getMessage();
}

$ftp = new FtpWrapper($connection);

关闭连接

$connection->close();

FTP 包装器

  • get($localFile, $remoteFile)
  • put($remoteFile, $localFile)
  • makedir($path)
  • removedir($path)
  • nlist($directory = false)
  • rawlist($directory = false, $recursive = false)
  • rename($oldname, $newname)
  • delete($path)

 GET

自动创建本地目录递归

$localFile = 'demofile.txt';
$remoteFile = 'folder/demofile.txt'
$ftp->get($localFile, $remoteFile);

 PUT

在 FTP 上自动创建目录递归

$ftp->put($remoteFile, $localFile);

 MAKEDIR

在 FTP 上自动创建目录递归

$path = 'folder/subfolder1/subfolder2';
$ftp->makedir($path);

 REMOVEDIR

递归删除目录

$path = 'folder';
$ftp->removedir($path);

 NLIST

$list = $ftp->nlist($path);

输出

array(7) {
  [0]=>
  string(1) "."
  [1]=>
  string(2) ".."
  [2]=>
  string(4) "demo"
  [3]=>
  string(9) "demo1.txt"
  [4]=>
  string(9) "demo2.txt"
  [5]=>
  string(7) "folder"
}

 RAWLIST

$list = $ftp->rawlist($path, $recursive);

输出

array(48) {
  [0]=>
  string(63) "drwxr-xr-x    4 user      user            4096 May 12 05:53 ."
  [1]=>
  string(64) "drwxr-xr-x    4 user      user            4096 May 12 05:53 .."
  [2]=>
  string(66) "drwxr-xr-x    2 user      user            4096 May 12 05:56 demo"
  [3]=>
  string(71) "-rw-r--r--    1 user      user            1544 May 12 05:07 demo1.txt"
  [4]=>
  string(71) "-rw-r--r--    1 user      user            1544 May 12 05:07 demo2.txt"
  [5]=>
  string(69) "drwxr-xr-x    3 user      user            4096 May 12 05:07 folder"
  [6]=>
  string(0) ""
  ....

 RENAME

$oldname = 'folder/subfolder/filetochange.txt';
$newname = 'folder/subfolder/filechange.txt';
$ftp->rename($oldname, $newname);

 DELETE

$path_file = 'folder/subfolder/filechange.txt';
$ftp->delete($path_file);

许可证

MIT 许可证 (MIT)

版权 (c) 2016

在此特此授予任何人获得此软件及其相关文档文件(“软件”)副本的许可,免费使用软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许向软件提供者提供软件的人这样做,但受以下条件约束:

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是在合同行为、侵权行为或其他行为中,无论是因软件或软件的使用或任何其他方式引起的。