Php connects to the sftp server to download all files in the folder

excuse me, how does php connect to the sftp server to download all the files in the folder? I only see that php provides the function to download a single file, or how to traverse the directory of the folder under the sftp server?

Php
Mar.13,2021

according to your problem description, you seem to want to scan the folder through php, and then download the files in the folder one by one.

//php
//
scandir
//
is_dir

my implementation code

function do_search($path,$result){
        $dir = scandir($path);
        foreach ($dir as $key => $value) {
                if ($value!='.'&&$value!='..') {
                        //is dir
                        if (is_dir($path.'/'.$value)) {
                                $folder_info['folder'][]=$path.$value.'/';
                                $result = do_search($path.$value.'/',$result);
                        }
                        //not dir
                        else{
                                array_push($result,$path.$value);
                        }
                }
        }
        //$folder_info"" 
        //return $folder_info;
        //$result"" 
        return $result;
}

//$result
$result =array();

//$pathlinux/var/www/html/
$all_file_info = do_search($path,$result);
//$all_file_infodo_searchnot dir
Menu