PHP & Others

처음 만든 클래스 입니다.(FTP)

페이지 정보

본문

처음 으로 클래스라는 것을 만들어 보았습니다.
처음 만든거라 문법이라든지 효율성 기타 여러가지 이상한 부분이 많을 거라 생각이 들어
여러분들의 도움을 얻고자 올립니다. 수정할 부분과 많은 조언 부탁드립니다.
이상하게 만들었다 욕하지 마시고 도움을 부탁드립니다. 감사합니다.

class Ftp_control {
    //멤버 변수 선언 부
    var $FHost;                    #접속 HOST
    var $FUser;                    #접속 ID
    var $FPasswd;                #접속 패스워드
    var $Server_port = "21";    #FTP 포터
    var $Fconnect;                #FTP stream
    var $local_file;
    var $remote_file;
    var $del_file;
    var $del_dir;
    var $make_dir;
    var $dir_per;
    var $read_dir;
    var $file_list = array();
    function Ftp_control($FHost,$FUser,$FPasswd,$Server_port) {
        if(!$FHost || !$FUser || !$FPasswd || !$FPasswd) {
            $msg = "Connect Infomation Fail";
            $this -> setError($msg);
        }
        else {
            if(!($connect = ftp_connect($FHost, $server_port))) $this -> setError("NO Search HOST"); 
            if(!ftp_login($connect, $FUser, $FPasswd)) $this -> setError("Login Information Not agree");
            $this->Fconnect = $connect;
        }
    }

    function upload_file() {
        $fp = $this->Fconnect;
        $ref = $this->remote_file;
        $lof = $this->local_file;
       
        if(!$fp || !$ref || !$lof) $this -> setError("업로드할 파일 정보가 전송되지 않았습니다. ");
        if(!ftp_put($fp,$ref ,$lof ,FTP_BINARY )) $this -> setError("FTP 파일전송중 에러가 발생 했습니다.");
    }

    function download_file() {
        $fp = $this -> Fconnect;
        $ref = $this -> remote_file;
        $lof = $this -> local_file;
        if(!ftp_get($fp,$lof,$ref,FTP_BINARY)) $this -> setError("FTP 파일다운로드중 에러가 발생 했습니다");
    }
   
    function delete_file() {
        $fp = $this -> Fconnect;
        $del = $this -> del_file;
        if(!$fp || !$del) $this -> setError("삭제할 파일 정보가 전송되지 않았습니다.");
        if(!ftp_delete($fp,$del)) $this -> setError("파일삭제중 오류가 발생 했습니다.");
    }
   
    function delete_dir() {
        $fp = $this -> Fconnect;
       
        //$fdir = $this -> del_dir;
        //if(!($dfileList = ftp_nlist($fp,$fdir))) $this -> setError("삭제할 디렉토리가 존재 하지 않습니다.");
        $this -> file_directory();
        $dfileList = $this -> file_list;
        while(list($k,$v) = each($dfileList)) {
            if(!ftp_delete($fp,$v)) $this -> setError("디렉토리 파일 삭제 오류");
        }
        if(!ftp_rmdir($fp,$fdir)) $this -> setError("디렉토리 삭제 오류");
    }

    function make_directory() {
        $fp = $this -> Fconnect;
        $mdir = $this -> make_dir;
        $per = $this -> dir_per;
        if(!ftp_mkdir($fp,$mdir)) $this -> setError("디렉토리 생성 오류");
        //if(!ftp_site($fp, "chown nobody.nobody $mdir")) $this -> setError("소유권 변경 오류");
        if(!ftp_site($fp, "chmod $per $mdir")) $this -> setError("퍼미션 변경 오류");
    }
   
    function file_directory() {
        $fp = $this -> Fconnect;
        $rdir = $this -> read_dir;
        if(!($dfileList = ftp_nlist($fp,$rdir))) $this -> setError("디렉토리 출력 오류");
        $this -> file_list = $dfileList;
    }

    function closeFtp() {
        ftp_quit($this->Fconnect);
    }

    function setError($msg) {
        echo "FTP Error : ".$msg."<br>";
        exit;
    }
}

관련자료

등록된 댓글이 없습니다.
Today's proverb
좋은 예절이란 무엇일까? 그것은 남의 나쁜 예절을 용서하는 것이다. <이스라엘 속담>