class Rake::FtpUploader

Manage the uploading of files to an FTP account.
###################################################################

def close

Close the uploader.
def close
  @ftp.close
end

def connect(path, host, account, password)

When the block is complete, close the uploader.
Create an uploader and pass it to the given block as +up+.
def connect(path, host, account, password)
  up = self.new(path, host, account, password)
  begin
    yield(up)
  ensure
    up.close
  end
end

def initialize(path, host, account, password)

path of the uploader.
using the given account and password. +path+ will be the root
Create an FTP uploader targeting the directory +path+ on +host+
def initialize(path, host, account, password)
  @created = Hash.new
  @path = path
  @ftp = Net::FTP.new(host, account, password)
  makedirs(@path)
  @ftp.chdir(@path)
end

def makedirs(path)

Create the directory +path+ in the uploader root path.
def makedirs(path)
  route = []
  File.split(path).each do |dir|
    route << dir
    current_dir = File.join(route)
    if @created[current_dir].nil?
      @created[current_dir] = true
      $stderr.puts "Creating Directory  #{current_dir}" if @verbose
      @ftp.mkdir(current_dir) rescue nil
    end
  end
end

def upload(file)

Upload a single file to the uploader's root path.
def upload(file)
  $stderr.puts "Uploading #{file}" if @verbose
  dir = File.dirname(file)
  makedirs(dir)
  @ftp.putbinaryfile(file, file) unless File.directory?(file)
end

def upload_files(wildcard)

path.
Upload all files matching +wildcard+ to the uploader's root
def upload_files(wildcard)
  fail "OUCH"
  Rake.glob(wildcard).each do |fn|
    upload(fn)
  end
end