Jump to content

Functions, Folders and Files (Help needed)


Ruzzas

Recommended Posts

I've got two functions.

 

One which lists the folders/files in a folder (remotely)

 

One which downloads all them (recursively)

 

I need you guys to help me make:

 

The downloader (mkdir) folders if they arn't already on the local drive, and to keep checking if there's a folder, If so check inside and make sure it empty, else add the files from that to the download list.

 

The remote lister could probably be rewritten a little cleaner. But I'm going to leave it up to you guys.

 

I'm confused on doing this and would appreciate it if you could give a few minutes to help me.

 

Code:

 

function RemoteListDirectory($Directory, $Array = array(), $First = True){
    global $Server;
    global $Connection;
    if($Connection){
        if($First){
            ftp_chdir($Connection, $Directory);
        }
        if(ftp_size($Connection, $Directory) != -1){
            if($First){
                return False; 
            }
            $Array[] = $Directory;
            return $Array;
       }else{
            $Contents = ftp_nlist($Connection, $Directory);
            if(!count($Contents)){
                $Array[] = $Directory;
                return $Array;
            }
            foreach($Contents as $File){
                $Array[] = RemoteListDirectory($File, $Array, False);
            }
            
            if($Array = Strip($Server['RDirectory'], ".", $Array)){
                return $Array;
            }else{
                return False;
            }
        }
    }else{
        return False;
    }
}

function Download($Array = array(), $Recursive = False){
    global $Connection;
    if($Connection){
        for($I=0;$I<count($Array);$I++){
            if($Array[$I] != ""){
                if($ftp_size($Connection, $Array[$I] == -1)){
                    $Array = array_merge($Array, Download($Array[$I], True));
                }else{
                    ftp_get($Connection,$Array[$I],$Array[$I],FTP_BINARY);
                } 
                if($Recursive){
                    $Directory = ftp_pwd($Connection);
                    $Array[] = "$Directory/$Array[$I]";
                }else{
                    $Array[] = $Array[$I];
                }
            }
        }
    }else{
        return False;
    }
    return $Array;
}

Link to comment
https://forums.phpfreaks.com/topic/206681-functions-folders-and-files-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.