ftp_deploy.rb
def delete_ftp_dir(ftp, dir, skip=[])

    # Get list of contents and their parameters (ls -l).
    files_list = ftp.list(dir)

    # Iterate over the directory contents and delete files. Subdirectories are
    # deleted recursively.
    ftp.nlst(dir).each_with_index do |file, index|

        # Skip . and ..
        if file == "." or file == ".."
            next
        end

        # Skip any specified files or folders
        if skip.include?(file)
            next
        end

        # Create full path to item
        file_path = File.join(dir, file)

        # Based on the number of links determine if it is a file or directory.
        nlinks = files_list[index].split(" ")[1].to_i
        if nlinks < 2
            puts "Deleting:".red + " #{file_path}"
            ftp.delete(file_path)
        else
            delete_ftp_dir(ftp, file_path)
            puts "Deleting:".red + " #{file_path}"
            ftp.rmdir(file_path)
        end

    end

end
# Recursively delete the contents of the specified directory.
Recursively delete the contents of the specified directory.
Recursively delete the contents of the specified directory .
def delete_ftp_dir(ftp, dir, skip=[])
    files_list = ftp.list(dir)
    ftp.nlst(dir).each_with_index do |file, index|
        if file == "." or file == ".."
            next
        end
        if skip.include?(file)
            next
        end
        file_path = File.join(dir, file)
        nlinks = files_list[index].split(" ")[1].to_i
        if nlinks < 2
            puts "Deleting:".red + " #{file_path}"
            ftp.delete(file_path)
        else
            delete_ftp_dir(ftp, file_path)
            puts "Deleting:".red + " #{file_path}"
            ftp.rmdir(file_path)
        end
    end
end
def delete_ftp_dir ( ftp , dir , skip = [ ] ) files_list = ftp . list ( dir ) ftp . nlst ( dir ) . each_with_index do | file , index | if file == "." or file == ".." next end if skip . include? ( file ) next end file_path = File . join ( dir , file ) nlinks = files_list [ index ] . split ( " " ) [ 1 ] . to_i if nlinks < 2 puts "Deleting:" . red + " #{file_path}" ftp . delete ( file_path ) else delete_ftp_dir ( ftp , file_path ) puts "Deleting:" . red + " #{file_path}" ftp . rmdir ( file_path ) end end end
Recursively delete the contents of the specified directory.
Recursively delete the contents of the specified directory .
# Get list of contents and their parameters (ls -l). # Iterate over the directory contents and delete files. Subdirectories are # deleted recursively. # Skip . and .. # Skip any specified files or folders # Create full path to item # Based on the number of links determine if it is a file or directory.
ftp
dir
skip