FTP文件夹到本地使用PHP

时间:2015-05-25 16:39:45

标签: php ftp

我想在我项目的文件夹(localhost)中制作ftp的副本,所以我需要指定source_folder和dest_folder。我的问题是我的代码只保存项目根目录中的所有文件,我想复制我的ftp文件夹" /"进入我的" ./ copy_data"我当地项目中的文件夹。

这是我的代码:

 function ftp_sync ($dir) {

    if ($dir != ".") {
        if (ftp_chdir($this->conn, $dir) == false) {
            echo ("Change Dir Failed: $dir<BR>\r\n");
            return;
        }
        if (!(is_dir($dir)))
            mkdir($dir);
        chdir ($dir);
    }

    $contents = ftp_nlist($this->conn, ".");
    foreach ($contents as $file) {

        if ($file == '.' || $file == '..')
            continue;

        if (@ftp_chdir($this->conn, $file)) {
            ftp_chdir ($this->conn, "..");
            $this->ftp_sync ($file);
        }
        else{
            //ftp_get($this->conn, $file, $file, FTP_BINARY);
            ftp_get($this->conn, $file, $file, FTP_BINARY);
        }

    }

    ftp_chdir ($this->conn, "..");
    chdir ("..");

}


    ftp_sync('.');

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

你可以执行bash命令从php到zip,复制和移动目标文件夹是我的推荐

$message=shell_exec("/var/www/scripts/testscript 2>&1");
print_r($message);