使用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<? //设置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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<?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.