spyric/ftpclient

此软件包已被废弃,不再维护。未建议替代软件包。

PHP的FTP客户端

0.0.1 2016-08-14 19:52 UTC

This package is auto-updated.

Last update: 2021-02-27 09:44:41 UTC


README

由Egor Talantsev编写。(http://www.ananas-web.ru/

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!
}

贡献

发现了错误或知道更好的方法?只需fork并修复它。然后发送pull请求。

特别感谢

特别感谢Melih Ucar,他的软件包被用作此软件包的基础。