Manage the uploading of files to an FTP account.
Create an uploader and pass it to the given block as up. When the block is complete, close the uploader.
# File lib/rake/contrib/ftptools.rb, line 95 95: def connect(path, host, account, password) 96: up = self.new(path, host, account, password) 97: begin 98: yield(up) 99: ensure 100: up.close 101: end 102: end
Create an FTP uploader targetting the directory path on host using the given account and password. path will be the root path of the uploader.
# File lib/rake/contrib/ftptools.rb, line 108 108: def initialize(path, host, account, password) 109: @created = Hash.new 110: @path = path 111: @ftp = Net::FTP.new(host, account, password) 112: makedirs(@path) 113: @ftp.chdir(@path) 114: end
Close the uploader.
# File lib/rake/contrib/ftptools.rb, line 139 139: def close 140: @ftp.close 141: end
Create the directory path in the uploader root path.
# File lib/rake/contrib/ftptools.rb, line 117 117: def makedirs(path) 118: route = [] 119: File.split(path).each do |dir| 120: route << dir 121: current_dir = File.join(route) 122: if @created[current_dir].nil? 123: @created[current_dir] = true 124: puts "Creating Directory #{current_dir}" if @verbose 125: @ftp.mkdir(current_dir) rescue nil 126: end 127: end 128: end
Upload a single file to the uploader’s root path.
# File lib/rake/contrib/ftptools.rb, line 146 146: def upload(file) 147: puts "Uploading #{file}" if @verbose 148: dir = File.dirname(file) 149: makedirs(dir) 150: @ftp.putbinaryfile(file, file) unless File.directory?(file) 151: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.