moxar/ftp

该软件包最新版本(3)没有可用的许可证信息。

用于Laravel的FTP库

该软件包的规范仓库似乎已不存在,因此软件包已被冻结。

维护者

详细信息

github.com/moxar/ftp

3 2015-02-03 10:00 UTC

This package is not auto-updated.

Last update: 2024-01-23 01:43:17 UTC


README

安装

这是一个基于Laravel框架的php库。要安装,请将以下行添加到composer,然后运行composer update。

./composer.json

	{
		...
		"require": {
			"moxar/ftp": "dev-master"
		},
		...
	}

别忘了将FtpServiceProvider添加到您的config/app.pphp文件中。我还建议您使用别名。负责FTP连接的类称为connection

./config/app.php

	return array(
		...
		'providers' => array(
			...
			'Moxar\Ftp\FtpServiceProvider',
			...
		),
		...
		'aliases' => array(
			...
			'Ftp' => 'Moxar/Ftp/Facades/Connection',
			...
		),
		...
	);

配置

该软件包的行为类似于Illuminate提供的DB软件包。您需要一个如下的配置文件。

./config/ftp.php

	
	return [
		'default' => 'some_connection',				// This the key of the default connection.
		
		'connections' => [
			
			'some_connection' => [					// A connection identified by a slug
				'host' => 'localhost',
				'port' => '21',
				'username' => 'my_user_name',
				'password' => 'my_password',
				'protocol' => 'ftp',				// You can use ftp, sftp or ftps.
													// However, sftp and ftps are not well implemented. Expect bugs.
			],
			'some_other_connection' => [			// Another connection identified by another slug
				...
			],
		],
	];

使用

FTP方法

安装和配置完成后,您可以使用该软件包。以下是一些使用示例。

	use Moxar\Ftp\Facades\Connection as Ftp;
	
	// Uploads and Downloads
	Ftp::upload($local, $remote); 		// uploads the file or directory $local to the location $remote (recursive).
	Ftp::download($remote, $local);		// downloads the file or directory $remote to the location $local (recursive).
	
	// Readings
	Ftp::isDirectory($path);			// tells you if $path is a directory.
	Ftp::isFile($path);					// tells you if $path is a file.
	Ftp::exists($path);					// tells you if $path exists.
	Ftp::files($path); 					// returns all files and directories within $path as an array.
	
	// Writings
	Ftp::makedirectory($path);			// creates a directory at the $path location.
	Ftp::clean($path);					// removes all contents inside a $path directory (recursive).
	Ftp::delete($path);					// removes the file or directory from the given $path location (recursive).
	Ftp::move($old, $new);				// moves the $old file or directory to $new location.
	Ftp::copy($old, $new, $buffer)		// copies the content of $old to $new using a local $buffer folder.
	
	// Connection
	Ftp::connection('some_connection')
		->upload($local, $remove);		// switches the $connection to the defined slug and uses the upload method.

普通方法

由于存在__call()魔法方法,该库包含了所有PHP普通函数。任何被调用的普通ftp_method都会使用当前连接作为ftp_stream参数。以下是使用示例。

	use Moxar\Ftp\Facades\Connection as Ftp;
	
	Ftp::ftp_chmod(755, $file);
	Ftp::ftp_mkdir($path);