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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.