In Files

  • rake/contrib/ftptools.rb

Rake::FtpUploader

Manage the uploading of files to an FTP account.

Attributes

verbose[RW]

Log uploads to standard output when true.

Public Class Methods

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 rake/contrib/ftptools.rb, line 105
def initialize(path, host, account, password)
  @created = Hash.new
  @path = path
  @ftp = Net::FTP.new(host, account, password)
  makedirs(@path)
  @ftp.chdir(@path)
end
            

Public Instance Methods

close() click to toggle source

Close the uploader.

 
               # File rake/contrib/ftptools.rb, line 136
def close
  @ftp.close
end
            
connect(path, host, account, password) 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 rake/contrib/ftptools.rb, line 92
def connect(path, host, account, password)
  up = self.new(path, host, account, password)
  begin
    yield(up)
  ensure
    up.close
  end
end
            
makedirs(path) click to toggle source

Create the directory path in the uploader root path.

 
               # File rake/contrib/ftptools.rb, line 114
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
            
upload_files(wildcard) click to toggle source

Upload all files matching wildcard to the uploader’s root path.

 
               # File rake/contrib/ftptools.rb, line 129
def upload_files(wildcard)
  Dir[wildcard].each do |fn|
    upload(fn)
  end
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus