Class: Rake::FtpUploader
- Inherits:
-
Object
- Object
- Rake::FtpUploader
- Defined in:
- lib/rake/contrib/ftptools.rb
Overview
Manage the uploading of files to an FTP account.
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Log uploads to standard output when true.
Class Method Summary collapse
-
.connect(path, host, account, password) ⇒ Object
Create an uploader and pass it to the given block as
up
.
Instance Method Summary collapse
-
#close ⇒ Object
Close the uploader.
-
#initialize(path, host, account, password) ⇒ FtpUploader
constructor
Create an FTP uploader targeting the directory
path
onhost
using the given account and password. -
#makedirs(path) ⇒ Object
Create the directory
path
in the uploader root path. -
#upload_files(wildcard) ⇒ Object
Upload all files matching
wildcard
to the uploader’s root path.
Constructor Details
#initialize(path, host, account, password) ⇒ FtpUploader
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.
92 93 94 95 96 97 98 |
# File 'lib/rake/contrib/ftptools.rb', line 92 def initialize(path, host, account, password) @created = Hash.new @path = path @ftp = Net::FTP.new(host, account, password) makedirs(@path) @ftp.chdir(@path) end |
Instance Attribute Details
#verbose ⇒ Object
Log uploads to standard output when true.
74 75 76 |
# File 'lib/rake/contrib/ftptools.rb', line 74 def verbose @verbose end |
Class Method Details
.connect(path, host, account, password) ⇒ Object
Create an uploader and pass it to the given block as up
. When the block is complete, close the uploader.
79 80 81 82 83 84 85 86 |
# File 'lib/rake/contrib/ftptools.rb', line 79 def connect(path, host, account, password) up = self.new(path, host, account, password) begin yield(up) ensure up.close end end |
Instance Method Details
#close ⇒ Object
Close the uploader.
123 124 125 |
# File 'lib/rake/contrib/ftptools.rb', line 123 def close @ftp.close end |
#makedirs(path) ⇒ Object
Create the directory path
in the uploader root path.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rake/contrib/ftptools.rb', line 101 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 |