Class | Rake::FtpUploader |
In: |
lib/rake/contrib/ftptools.rb
|
Parent: | Object |
Manage the uploading of files to an FTP account.
verbose | [RW] | Log uploads to standard output when true. |
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