PHP写的ftp类

ftp类(myftp.php)

<?php

class myftp {

    var $connector;
    var $getback;

    function connect($ftp_server, $uname, $passwd){
    // Baut grundlegende FTP Connection auf
        $this->connector = @ftp_connect($ftp_server);
        $this->login_result = @ftp_login($this->connector, "$uname", "$passwd");
        if ((!$this->connector) ││ (!$this->login_result))
        {
                echo "FTP connection has failed! n";
                echo "Attempted to connect to $ftp_server for user $uname n";
                die;
            } else {
                echo "Connected to $ftp_server, for user $uname n";
            }
    }

    function lastmodtime($value){
        $getback = ftp_mdtm ($this->connector,$value);
        return $getback;
    }

    function changedir($targetdir){
        $getback = ftp_chdir($this->connector, $targetdir);
        return $getback;
    }
    function getdir(){
        $getback = ftp_pwd($this->connector);
        return $getback;
    }

    function get_file_list($directory){
        $getback = ftp_nlist($this->connector, $directory);
        return $getback;
    }

    function get_file($file_to_get, $mode, $mode2){
        $realfile = basename($file_to_get);
        $filename = $realfile;

        $checkdir = @$this->changedir($realfile);
        if ($checkdir == TRUE){
            ftp_cdup($this->connector);
            echo "n[DIR] $realfile";
        }else{
            echo "..... ". $realfile ."n";
            $getback = ftp_get($this->connector, $filename, $realfile, $mode);
            if ($mode2){
                $delstatus = ftp_del&#101;te($this->connector, $file_to_get);
                if ($delstatus == TRUE){
                    echo "File $realfile on $host del&#101;ted n";
                }
            }
        }
        return $getback;
    }

    function mode($pasvmode){
        $result = ftp_pasv($this->connector, $pasvmode);
    }

    function ftp_bye(){
        ftp_quit($this->connector);
        return $getback;
    }
}

?>

<?php
flush();

$ftp_ini_datei         = $argv&#91;1&#93;;

require ('./ftp_class.php');
require ($ftp_ini_datei);

echo "nCronjob started : ";
echo date("d.m.Y  - H:i:s");
echo "n";

$newftp         = new myftp;

if(!$anonymous){
    $result     = $newftp->connect($host, $user, $password);
}else{
    $result        = $newftp->connect($host, "anonymous", "mymail@somewh&#101;re.com");
}

if (!$result){
    $mydir         = $newftp->changedir($remote_dir);
    $mydir        = $newftp->getdir();
    $merkold_dir    = getcwd();
    chdir($local_dir);
    $mylist     = Array();
    $mylist     = $newftp->get_file_list($mydir);



    for ($i=0; $i < sizeof($mylist); $i++)
    {
        $result = $newftp->get_file($mylist[$i], $mymode, $del&#101;te);
    }

    $result     = $newftp->ftp_bye();

}else{

    echo "----------------------------------n";
    echo "no connection established :(      n";
    echo "----------------------------------n";

}

echo "nnCronjob stopped : ";
echo date("d.m.Y - H:i:s");
echo "n";
?>

关注公众号,手机阅读更方便。程序员的阅微草堂:

知识共享许可协议莿鸟栖草堂CFC4N 创作,采用 知识共享 署名-非商业性使用-相同方式共享(3.0未本地化版本)许可协议进行许可。基于http://www.cnxct.com上的作品创作。转载请注明转自:PHP写的ftp类

发表评论

电子邮件地址不会被公开。 必填项已用*标注