使用方法
<?
//设置PHP超时
set_time_limit(200);
//包含类文件
require('ftp.class.php');
//使用
$ftp = new FTP('www.domain.com','username','password'); //连接FTP
$ftp->ftpMkDir('www.domain.com/directory-name'); //创建文件夹
$ftp->ftpFolderPermission('www.domain.com/directory-name','0777'); //更改权限
$ftp->ftpCopyFile('www.domain.com/directory-name/file.php','file.php'); //复制文件
$ftp->ftpClose(); // 关闭FTP连接
?>
完整的类文件 ftp.class.php
<?php
//Full PHP FTP Class
class FTP {
private $host;
private $user;
private $pass;
private $conn;
private $dirToCreate;
private $folderChmod;
private $permission;
private $remoteFile;
private $localFile;
public function __construct($host,$user,$pass){
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->conn = ftp_connect($this->host) or die("Could not connect to $host");
ftp_login($this->conn,$this->user,$this->pass);
echo "connected ok ".$this->host;
}
function ftpClose() {
ftp_close($this->conn);
}
function ftpMkDir($dirToCreate){
$this->dirToCreate = $dirToCreate;
@ftp_mkdir($this->conn,$dirToCreate);
if(file_exists($this->dirToCreate))
{
return false;
} else {
echo "<p>Directory: $dirToCreate created</p>n";
}
}
function ftpFolderPermission($folderChmod,$permission){
$this->folderChmod = $folderChmod;
$this->permission = $permission;
if (ftp_chmod($this->conn, $this->permission, $this->folderChmod) !== false)
{
echo "<p>$folderChmod chmoded successfully to ".$this->permission."</p>n";
}
}
function ftpCopyFile($remoteFile,$localFile){
$this->remoteFile = $remoteFile;
$this->localFile = $localFile;
if (ftp_put($this->conn,$this->remoteFile,$this->localFile,FTP_ASCII))
{
echo "<p>successfully uploaded $localFile to $remoteFile</p>n";
} else {
echo "<p>There was a problem while uploading $remoteFile</p>n";
}
}
}
?>
有使用问题留言告知!
博主 你的源码程序和官方演示不一样啊 功能少了些 可以发一份 和官方一样的吗 谢谢….
哪个程序?
Pcfile.cn是自用版 不提供的
发布的是简版 可以满足大部分需求的
Hi there mates, its enormous post regarding tutoringand fully defined, keep it up all the time.