class FtpUploader
Manage the uploading of files to an FTP account.
Attributes
Log uploads to standard output when true.
Public Class Methods
Source
# File lib/rake/contrib/ftptools.rb 92 def connect(path, host, account, password) 93 up = self.new(path, host, account, password) 94 begin 95 yield(up) 96 ensure 97 up.close 98 end 99 end
Create an uploader and pass it to the given block as up
. When the block is complete, close the uploader.
Source
# File lib/rake/contrib/ftptools.rb 105 def initialize(path, host, account, password) 106 @created = Hash.new 107 @path = path 108 @ftp = Net::FTP.new(host, account, password) 109 makedirs(@path) 110 @ftp.chdir(@path) 111 end
Create an FTP uploader targeting the directory path
on host
using the given account and password. path
will be the root path of the uploader.
Public Instance Methods
Source
# File lib/rake/contrib/ftptools.rb 136 def close 137 @ftp.close 138 end
Close the uploader.
Source
# File lib/rake/contrib/ftptools.rb 114 def makedirs(path) 115 route = [] 116 File.split(path).each do |dir| 117 route << dir 118 current_dir = File.join(route) 119 if @created[current_dir].nil? 120 @created[current_dir] = true 121 $stderr.puts "Creating Directory #{current_dir}" if @verbose 122 @ftp.mkdir(current_dir) rescue nil 123 end 124 end 125 end
Create the directory path
in the uploader root path.
Source
# File lib/rake/contrib/ftptools.rb 129 def upload_files(wildcard) 130 Dir[wildcard].each do |fn| 131 upload(fn) 132 end 133 end
Upload all files matching wildcard
to the uploader’s root path.