此软件包的最新版本(v1.2.1)没有提供许可证信息。

用于访问FTP服务器的易用库

v1.2.1 2018-05-17 19:34 UTC

This package is auto-updated.

Last update: 2024-09-27 16:38:16 UTC


README

Downloads this Month Latest Stable Version License

FTP for PHP 是一个非常小且易于使用的库,用于访问FTP服务器。

它需要PHP 5.0或更高版本,并受新BSD许可证的许可。您可以从我们的 GitHub 仓库 获取最新版本,或通过Composer安装。

php composer.phar require dg/ftp-php

用法

打开到指定主机的FTP连接

$ftp = new Ftp;
$host = 'ftp.example.com';
$ftp->connect($host);

使用用户名和密码登录

$ftp->login($username, $password);

上传文件

$ftp->put($destination_file, $source_file, FTP_BINARY);

关闭FTP流

$ftp->close();
// or simply unset($ftp);

Ftp在操作失败时抛出异常。因此,您可以简单地这样做

try {
	$ftp = new Ftp;
	$ftp->connect($host);
	$ftp->login($username, $password);
	$ftp->put($destination_file, $source_file, FTP_BINARY);

} catch (FtpException $e) {
	echo 'Error: ', $e->getMessage();
}

另一方面,如果您想静默捕获可能的异常,请调用带有前缀'try'的方法

$ftp->tryDelete($destination_file);

当连接意外中断时,您可以使用方法 $ftp->reconnect() 重新建立连接。

(c) David Grudl, 2008, 2014 (http://davidgrudl.com)