PHP FTP 类

WBOY
Lepaskan: 2016-07-29 09:13:59
asal
1030 orang telah melayarinya
<?php /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FTP
 *
 * @author admin
 */
class FTP {

    public $conn;
    public $username;
    public $password;
    public $ftp_url;

    public function __construct($username = &#39;&#39;, $passwrod = &#39;&#39;, $url = &#39;127.0.0.1&#39;) {
        $this->ftp_url = $url;
        $this->username = $username;
        $this->password = $passwrod;
    }

    //连接FTP服务器
    public function connect() {
        if (!($this->conn = ftp_connect($this->ftp_url))) {
            return false;
        } else {
            return true;
        }
    }

    //登录
    public function login() {
        if (!ftp_login($this->conn, $this->username, $this->password)) {
            return false;
        } else {
            return true;
        }
    }

    //获取服务器系统类型
    public function getSysType() {
        return ftp_systype($this->conn);
    }

    //获取当前目录
    public function getCurrentDir() {
        return ftp_pwd($this->conn);
    }

    //显示文件列表
    public function listFiles($dir_name = '.') {
        return ftp_nlist($this->conn, $dir_name);
    }

    //显示详细文件列表
    public function listFilesOfDetails($dir_name = '') {
        return ftp_rawlist($this->conn, $dir_name);
    }

    //下载文件
    public function downloadFile($local = '', $remote = '', $type = FTP_ASCII) {
        if (ftp_get($this->conn, $local, $remote, $type)) {
            return true;
        } else {
            return false;
        }
    }

    //<strong>上传文件</strong>
    public function uploadedFile($remote, $local, $type = FTP_ASCII) {
        if (ftp_put($this->conn, $remote, $local, $type)) {
            return true;
        } else {
            return false;
        }
    }

    //建立目录
    public function createDir($dirname) {
        return ftp_mkdir($this->conn, $dirname);
    }

    //切换目录
    public function chdir($dirname) {
        return ftp_chdir($this->conn, $dirname);
    }

    //删除目录
    public function rmdir($dirname) {
        return ftp_rmdir($this->conn, $dirname);
    }

    //退出
    public function quitFTP() {
        return ftp_quit($this->conn);
    }

}
Salin selepas log masuk

.

以上就介绍了PHP FTP 类,包括了上传文件方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!