Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP将文件夹FTP到本地_Php_Ftp - Fatal编程技术网

使用PHP将文件夹FTP到本地

使用PHP将文件夹FTP到本地,php,ftp,Php,Ftp,我想在我的项目(localhost)的文件夹中复制ftp,所以我需要指定source\u文件夹和dest\u文件夹。我的问题是,我的代码只是将所有文件保存在项目的根目录中,我想将我的ftp文件夹“/”复制到本地项目的“/”复制数据“文件夹中 这是我的密码: function ftp_sync ($dir) { if ($dir != ".") { if (ftp_chdir($this->conn, $dir) == false) { e

我想在我的项目(localhost)的文件夹中复制ftp,所以我需要指定source\u文件夹和dest\u文件夹。我的问题是,我的代码只是将所有文件保存在项目的根目录中,我想将我的ftp文件夹“/”复制到本地项目的“/”复制数据“文件夹中

这是我的密码:

 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('.');
函数ftp\u sync($dir){
如果($dir!=“){
如果(ftp\u chdir($this->conn,$dir)==false){
echo(“更改目录失败:$Dir
\r\n”); 返回; } if(!(is_dir($dir))) mkdir($dir); chdir($dir); } $contents=ftp\u nlist($this->conn,“.”); foreach($file形式的内容){ 如果($file='.| |$file=''.') 继续; 如果(@ftp\u chdir($this->conn$file)){ ftp_chdir($this->conn,“…”); $this->ftp\u sync($file); } 否则{ //ftp\u get($this->conn,$file,$file,ftp\u二进制文件); ftp\u get($this->conn,$file,$file,ftp\u二进制文件); } } ftp_chdir($this->conn,“…”); chdir(“…”); } ftp_同步('.');

有人能帮我吗?

我建议您可以从php执行bash命令到zip,复制并移动目标文件夹

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

嗯,您只需在ftp会话中本地切换到退出文件夹。然后ftp get会将文件放在该目录中。为什么要先下载到错误的位置,然后压缩、移动和解压所有文件?为什么不立即存储在最终位置?