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

        if ($entries === false) {
            return $this->chmod($mode, $path);
        }

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

        foreach ($entries as $filename=>$props) {
            if ($filename == '.' || $filename == '..') {
                continue;
            }

            if (!isset($props['type'])) {
                return false;
            }

            $temp = $path . '/' . $filename;
            if ($props['type'] == NET_SFTP_TYPE_DIRECTORY) {
                if (!$this->_chmod_recursive($mode, $temp, $i)) {
                    return false;
                }
            } else {
                $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
                if (!$this->_send_sftp_packet(NET_SFTP_SETSTAT, pack('Na*a*', strlen($temp), $temp, $attr))) {
                    return false;
                }

                $i++;

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

        $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
        if (!$this->_send_sftp_packet(NET_SFTP_SETSTAT, pack('Na*a*', strlen($path), $path, $attr))) {
            return false;
        }

        $i++;

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

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

        if ($entries === false) {
            return $this->chmod($mode, $path);
        }

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

        foreach ($entries as $filename=>$props) {
            if ($filename == '.' || $filename == '..') {
                continue;
            }

            if (!isset($props['type'])) {
                return false;
            }

            $temp = $path . '/' . $filename;
            if ($props['type'] == NET_SFTP_TYPE_DIRECTORY) {
                if (!$this->_chmod_recursive($mode, $temp, $i)) {
                    return false;
                }
            } else {
                $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
                if (!$this->_send_sftp_packet(NET_SFTP_SETSTAT, pack('Na*a*', strlen($temp), $temp, $attr))) {
                    return false;
                }

                $i++;

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

        $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
        if (!$this->_send_sftp_packet(NET_SFTP_SETSTAT, pack('Na*a*', strlen($path), $path, $attr))) {
            return false;
        }

        $i++;

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

        return true;
    }
function _chmod_recursive ( $ mode , $ path , & $ i ) { if ( ! $ this -> _read_put_responses ( $ i ) ) { return false ; } $ i = 0 ; $ entries = $ this -> _list ( $ path , true , false ) ; if ( $ entries === false ) { return $ this -> chmod ( $ mode , $ path ) ; } // normally $entries would have at least . and .. but it might not if the directories
 // permissions didn't allow reading
 if ( empty ( $ entries ) ) { return false ; } foreach ( $ entries as $ filename => $ props ) { if ( $ filename == '.' || $ filename == '..' ) { continue ; } if ( ! isset ( $ props [ 'type' ] ) ) { return false ; } $ temp = $ path . '/' . $ filename ; if ( $ props [ 'type' ] == NET_SFTP_TYPE_DIRECTORY ) { if ( ! $ this -> _chmod_recursive ( $ mode , $ temp , $ i ) ) { return false ; } } else { $ attr = pack ( 'N2' , NET_SFTP_ATTR_PERMISSIONS , $ mode & 07777 ) ; if ( ! $ this -> _send_sftp_packet ( NET_SFTP_SETSTAT , pack ( 'Na*a*' , strlen ( $ temp ) , $ temp , $ attr ) ) ) { return false ; } $ i ++ ; if ( $ i >= 50 ) { if ( ! $ this -> _read_put_responses ( $ i ) ) { return false ; } $ i = 0 ; } } } $ attr = pack ( 'N2' , NET_SFTP_ATTR_PERMISSIONS , $ mode & 07777 ) ; if ( ! $ this -> _send_sftp_packet ( NET_SFTP_SETSTAT , pack ( 'Na*a*' , strlen ( $ path ) , $ path , $ attr ) ) ) { return false ; } $ i ++ ; if ( $ i >= 50 ) { if ( ! $ this -> _read_put_responses ( $ i ) ) { return false ; } $ i = 0 ; } return true ; }
Recursively chmods directories on the SFTP server

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.

@param Integer $mode
@param String $filename
@return Boolean
@access private
Recursively chmods directories on the SFTP server