dirlist example

if ( $this->is_file( $file ) ) {
                $mode = FS_CHMOD_FILE;
            } elseif ( $this->is_dir( $file ) ) {
                $mode = FS_CHMOD_DIR;
            } else {
                return false;
            }
        }

        // chmod any sub-objects if recursive.         if ( $recursive && $this->is_dir( $file ) ) {
            $filelist = $this->dirlist( $file );

            foreach ( (array) $filelist as $filename => $filemeta ) {
                $this->chmod( $file . '/' . $filename$mode$recursive );
            }
        }

        // chmod the file or directory.         if ( ! function_exists( 'ftp_chmod' ) ) {
            return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode$file ) );
        }

        

function copy_dir( $from$to$skip_list = array() ) {
    global $wp_filesystem;

    $dirlist = $wp_filesystem->dirlist( $from );

    if ( false === $dirlist ) {
        return new WP_Error( 'dirlist_failed_copy_dir', __( 'Directory listing failed.' )basename( $from ) );
    }

    $from = trailingslashit( $from );
    $to   = trailingslashit( $to );

    if ( ! $wp_filesystem->exists( $to ) && ! $wp_filesystem->mkdir( $to ) ) {
        return new WP_Error(
            'mkdir_destination_failed_copy_dir',
            
ob_end_clean();

    if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
    }

    if ( ! $wp_filesystem->wp_content_dir() ) {
        return new WP_Error( 'fs_no_content_dir', __( 'Unable to locate WordPress content directory (wp-content).' ) );
    }

    $temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/';
    $dirlist         = $wp_filesystem->dirlist( $temp_backup_dir );
    $dirlist         = $dirlist ? $dirlist : array();

    foreach ( array_keys( $dirlist ) as $dir ) {
        if ( '.' === $dir || '..' === $dir ) {
            continue;
        }

        $wp_filesystem->delete( $temp_backup_dir . $dir, true );
    }
}

if ( ! $recursive ) {
            return chgrp( $file$group );
        }

        if ( ! $this->is_dir( $file ) ) {
            return chgrp( $file$group );
        }

        // Is a directory, and we want recursive.         $file     = trailingslashit( $file );
        $filelist = $this->dirlist( $file );

        foreach ( $filelist as $filename ) {
            $this->chgrp( $file . $filename$group$recursive );
        }

        return true;
    }

    /** * Changes filesystem permissions. * * @since 2.5.0 * * @param string $file Path to the file. * @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, * 0755 for directories. Default false. * @param bool $recursive Optional. If set to true, changes file permissions recursively. * Default false. * @return bool True on success, false on failure. */

    public function check_package( $source$remote_source ) {
        global $wp_filesystem;

        if ( is_wp_error( $source ) ) {
            return $source;
        }

        // Check that the folder contains a valid language.         $files = $wp_filesystem->dirlist( $remote_source );

        // Check to see if a .po and .mo exist in the folder.         $po = false;
        $mo = false;
        foreach ( (array) $files as $file => $filedata ) {
            if ( str_ends_with( $file, '.po' ) ) {
                $po = true;
            } elseif ( str_ends_with( $file, '.mo' ) ) {
                $mo = true;
            }
        }

        
global $wp_filesystem;

        $this->skin->feedback( 'unpack_package' );

        if ( ! $wp_filesystem->wp_content_dir() ) {
            return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
        }

        $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';

        // Clean up contents of upgrade directory beforehand.         $upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
        if ( ! empty( $upgrade_files ) ) {
            foreach ( $upgrade_files as $file ) {
                $wp_filesystem->delete( $upgrade_folder . $file['name'], true );
            }
        }

        // We need a working directory - strip off any .tmp or .zip suffixes.         $working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );

        // Clean up working directory.         if ( $wp_filesystem->is_dir( $working_dir ) ) {
            

    public function delete( $file$recursive = false, $type = false ) {
        if ( 'f' === $type || $this->is_file( $file ) ) {
            return ssh2_sftp_unlink( $this->sftp_link, $file );
        }

        if ( ! $recursive ) {
            return ssh2_sftp_rmdir( $this->sftp_link, $file );
        }

        $filelist = $this->dirlist( $file );

        if ( is_array( $filelist ) ) {
            foreach ( $filelist as $filename => $fileinfo ) {
                $this->delete( $file . '/' . $filename$recursive$fileinfo['type'] );
            }
        }

        return ssh2_sftp_rmdir( $this->sftp_link, $file );
    }

    /** * Checks if a file or directory exists. * * @since 2.7.0 * * @param string $path Path to file or directory. * @return bool Whether $path exists or not. */
if ( $this->verbose ) {
            /* translators: 1: Folder to locate, 2: Folder to start searching from. */
            printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br />\n", $folder$base );
        }

        $folder_parts     = explode( '/', $folder );
        $folder_part_keys = array_keys( $folder_parts );
        $last_index       = array_pop( $folder_part_keys );
        $last_path        = $folder_parts[ $last_index ];

        $files = $this->dirlist( $base );

        foreach ( $folder_parts as $index => $key ) {
            if ( $index === $last_index ) {
                continue; // We want this to be caught by the next code block.             }

            /* * Working from /home/ to /user/ to /wordpress/ see if that file exists within * the current folder, If it's found, change into it and follow through looking * for it. If it can't find WordPress down that route, it'll continue onto the next * folder level, and see if that matches, and so on. If it reaches the end, and still * can't find it, it'll return false for the entire function. */
if ( $this->is_file( $file ) ) {
                $mode = FS_CHMOD_FILE;
            } elseif ( $this->is_dir( $file ) ) {
                $mode = FS_CHMOD_DIR;
            } else {
                return false;
            }
        }

        // chmod any sub-objects if recursive.         if ( $recursive && $this->is_dir( $file ) ) {
            $filelist = $this->dirlist( $file );

            foreach ( (array) $filelist as $filename => $filemeta ) {
                $this->chmod( $file . '/' . $filename$mode$recursive );
            }
        }

        // chmod the file or directory.         return $this->ftp->chmod( $file$mode );
    }

    /** * Gets the file owner. * * @since 2.5.0 * * @param string $file Path to the file. * @return string|false Username of the owner on success, false on failure. */
Home | Imprint | This part of the site doesn't use cookies.