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 81 81: def connect(path, host, account, password) 82: up = self.new(path, host, account, password) 83: begin 84: yield(up) 85: ensure 86: up.close 87: end 88: 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 94 94: def initialize(path, host, account, password) 95: @created = Hash.new 96: @path = path 97: @ftp = Net::FTP.new(host, account, password) 98: makedirs(@path) 99: @ftp.chdir(@path) 100: end
Close the uploader.
# File lib/rake/contrib/ftptools.rb, line 125 125: def close 126: @ftp.close 127: end
Create the directory path in the uploader root path.
# File lib/rake/contrib/ftptools.rb, line 103 103: def makedirs(path) 104: route = [] 105: File.split(path).each do |dir| 106: route << dir 107: current_dir = File.join(route) 108: if @created[current_dir].nil? 109: @created[current_dir] = true 110: puts "Creating Directory #{current_dir}" if @verbose 111: @ftp.mkdir(current_dir) rescue nil 112: end 113: end 114: end