class FtpUploader
Manage the uploading of files to an FTP account.
Attributes
verbose[RW]
Log uploads to standard output when true.
Public Class Methods
connect(path, host, account, password) { |up| ... }
click to toggle source
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 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
new(path, host, account, password)
click to toggle source
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.
# 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
Public Instance Methods
close()
click to toggle source
Close the uploader.
# File lib/rake/contrib/ftptools.rb 136 def close 137 @ftp.close 138 end
makedirs(path)
click to toggle source
Create the directory path
in the uploader root path.
# 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
upload_files(wildcard)
click to toggle source
Upload all files matching wildcard
to the uploader's root path.
# File lib/rake/contrib/ftptools.rb 129 def upload_files(wildcard) 130 Dir[wildcard].each do |fn| 131 upload(fn) 132 end 133 end