function _delete_recursive($path, &$i)
    {
        if (!$this->_read_put_responses($i)) {
            return false;
        }
        $i = 0;
        $entries = $this->_list($path, true);

        // normally $entries would have at least . and .. but it might not if the directories
        // permissions didn't allow reading
        if (empty($entries)) {
            return false;
        }

        unset($entries['.'], $entries['..']);
        foreach ($entries as $filename => $props) {
            if (!isset($props['type'])) {
                return false;
            }

            $temp = $path . '/' . $filename;
            if ($props['type'] == NET_SFTP_TYPE_DIRECTORY) {
                if (!$this->_delete_recursive($temp, $i)) {
                    return false;
                }
            } else {
                if (!$this->_send_sftp_packet(NET_SFTP_REMOVE, pack('Na*', strlen($temp), $temp))) {
                    return false;
                }
                $this->_remove_from_stat_cache($temp);

                $i++;

                if ($i >= NET_SFTP_QUEUE_SIZE) {
                    if (!$this->_read_put_responses($i)) {
                        return false;
                    }
                    $i = 0;
                }
            }
        }

        if (!$this->_send_sftp_packet(NET_SFTP_RMDIR, pack('Na*', strlen($path), $path))) {
            return false;
        }
        $this->_remove_from_stat_cache($path);

        $i++;

        if ($i >= NET_SFTP_QUEUE_SIZE) {
            if (!$this->_read_put_responses($i)) {
                return false;
            }
            $i = 0;
        }

        return true;
    }
function _delete_recursive($path, &$i)
    {
        if (!$this->_read_put_responses($i)) {
            return false;
        }
        $i = 0;
        $entries = $this->_list($path, true);

        // normally $entries would have at least . and .. but it might not if the directories
        // permissions didn't allow reading
        if (empty($entries)) {
            return false;
        }

        unset($entries['.'], $entries['..']);
        foreach ($entries as $filename => $props) {
            if (!isset($props['type'])) {
                return false;
            }

            $temp = $path . '/' . $filename;
            if ($props['type'] == NET_SFTP_TYPE_DIRECTORY) {
                if (!$this->_delete_recursive($temp, $i)) {
                    return false;
                }
            } else {
                if (!$this->_send_sftp_packet(NET_SFTP_REMOVE, pack('Na*', strlen($temp), $temp))) {
                    return false;
                }
                $this->_remove_from_stat_cache($temp);

                $i++;

                if ($i >= NET_SFTP_QUEUE_SIZE) {
                    if (!$this->_read_put_responses($i)) {
                        return false;
                    }
                    $i = 0;
                }
            }
        }

        if (!$this->_send_sftp_packet(NET_SFTP_RMDIR, pack('Na*', strlen($path), $path))) {
            return false;
        }
        $this->_remove_from_stat_cache($path);

        $i++;

        if ($i >= NET_SFTP_QUEUE_SIZE) {
            if (!$this->_read_put_responses($i)) {
                return false;
            }
            $i = 0;
        }

        return true;
    }
function _delete_recursive ( $ path , & $ i ) { if ( ! $ this -> _read_put_responses ( $ i ) ) { return false ; } $ i = 0 ; $ entries = $ this -> _list ( $ path , true ) ; // normally $entries would have at least . and .. but it might not if the directories // permissions didn't allow reading if ( empty ( $ entries ) ) { return false ; } unset ( $ entries [ '.' ] , $ entries [ '..' ] ) ; foreach ( $ entries as $ filename => $ props ) { if ( ! isset ( $ props [ 'type' ] ) ) { return false ; } $ temp = $ path . '/' . $ filename ; if ( $ props [ 'type' ] == NET_SFTP_TYPE_DIRECTORY ) { if ( ! $ this -> _delete_recursive ( $ temp , $ i ) ) { return false ; } } else { if ( ! $ this -> _send_sftp_packet ( NET_SFTP_REMOVE , pack ( 'Na*' , strlen ( $ temp ) , $ temp ) ) ) { return false ; } $ this -> _remove_from_stat_cache ( $ temp ) ; $ i ++ ; if ( $ i >= NET_SFTP_QUEUE_SIZE ) { if ( ! $ this -> _read_put_responses ( $ i ) ) { return false ; } $ i = 0 ; } } } if ( ! $ this -> _send_sftp_packet ( NET_SFTP_RMDIR , pack ( 'Na*' , strlen ( $ path ) , $ path ) ) ) { return false ; } $ this -> _remove_from_stat_cache ( $ path ) ; $ i ++ ; if ( $ i >= NET_SFTP_QUEUE_SIZE ) { if ( ! $ this -> _read_put_responses ( $ i ) ) { return false ; } $ i = 0 ; } return true ; }
Recursively deletes directories on the SFTP server

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.

@param string $path
@param int $i
@return bool
@access private
Recursively deletes directories on the SFTP server