melihucar/ftpclient

该包已被 弃用 且不再维护。未建议替代包。

PHP 的 FTPClient

安装数: 178,508

依赖: 0

建议者: 0

安全: 0

星标: 28

关注者: 4

分支: 15

开放问题: 1

语言:JavaScript

1.0 2013-11-27 01:25 UTC

This package is not auto-updated.

Last update: 2020-01-16 23:06:44 UTC


README

Build Status Total Downloads Latest Stable Version

Support via Gittip

由 Melih Ucar 编写。(http://www.melihucar.net/)

采用 MIT 许可证

用法

连接到 FTP 主机

$ftp = new FTPClient();
$ftp->connect($host, $ssl, $port, $timeout);
$ftp->login($username, $password);

使用被动模式:###

// This uses passive mode
$ftp->passive();

// If you want to disable using passive mode then
$ftp->passive(false);

使用二进制模式:###

// This uses binary mode, required for downloading binaries like zip
$ftp->binary(true);

// standard is false

###更改目录:###

// You can use fullpath to change dir
$ftp->changeDirectory('/root_dir/sub_dir');

// or you can use method chaining
$ftp->changeDirectory('/root_dir')->changeDirectory('sub_dir');

###切换到父目录:###

$ftp->changeDirectory('/root_dir/sub_dir');

$ftp->parentDirectory(); // now we are in /root_dir

###获取当前目录:###

// will return current path as string
$ftp->getDirectory();

###创建目录:###

// creates a directory in current path
$ftp->createDirectory($directoryName);

###删除目录:###

$ftp->removeDirectory($directoryName);

###获取目录列表:###

// returns directory list as array
$ftp->listDirectory();

###获取目录列表:###

// executes the FTP LIST command, and returns the result as an array
$ftp->rawlistDirectory($parameters, $recursive);

###删除文件:###

$ftp->delete($filename);

###返回文件大小(字节):###

$ftp->size($filename);

###返回最后修改时间:###

// returns unix timestamp
$ftp->modifiedTime($filename);

// returns formated
$ftp->modifiedTime($filename, $format);

###重命名文件或文件夹:###

$ftp->rename($current, $new);

###下载文件:###

// Downloads a file from remote host
$ftp->get($localFile, $remoteFile);

// Downloads file to an open file
$ftp->fget($handle, $remoteFile);

###上传文件:###

// Uploading local file to remote host
$ftp->put($remoteFile, $localFile);

// Uploading from an open file
$ftp->fput($remoteFile, $handle);

###获取服务器选项:###

$ftp->getOption(FTPClient::TIMEOUT_SEC);

###设置服务器选项:###

$ftp->setOption(FTPClient::TIMEOUT_SEC, 30);

###为上传文件分配空间:###

$ftp->allocate($filesize);

###更改文件和目录权限:###

$ftp->chmod($mode, $filename);

###在远程服务器上运行自定义命令:###

$ftp->exec($command);

###错误处理:### 如果操作失败,类将抛出异常。因此只需简单地使用 try-catch 块。

try {
    $ftp = new FTPClient();
    $ftp->connect($host, $ssl, $port, $timeout);
    $ftp->loginlogin($username, $password);
} catch (Exception $e) {
    // we got the error!
}

贡献

你发现了一个错误或知道更好的方法吗?只需简单地分支并修复它。然后发送拉取请求。