Class: Rake::FtpUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/contrib/ftptools.rb

Overview

Manage the uploading of files to an FTP account.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, host, account, password) ⇒ FtpUploader

Create an FTP uploader targetting the directory path on host using the given account and password. path will be the root path of the uploader.



94
95
96
97
98
99
100
# File 'lib/rake/contrib/ftptools.rb', line 94

def initialize(path, host, , password)
  @created = Hash.new
  @path = path
  @ftp = Net::FTP.new(host, , password)
  makedirs(@path)
  @ftp.chdir(@path)
end

Instance Attribute Details

#verboseObject

Log uploads to standard output when true.



76
77
78
# File 'lib/rake/contrib/ftptools.rb', line 76

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.



81
82
83
84
85
86
87
88
# File 'lib/rake/contrib/ftptools.rb', line 81

def connect(path, host, , password)
	up = self.new(path, host, , password)
	begin
	  yield(up)
	ensure
	  up.close
	end
end

Instance Method Details

#closeObject

Close the uploader.



125
126
127
# File 'lib/rake/contrib/ftptools.rb', line 125

def close
  @ftp.close
end

#makedirs(path) ⇒ Object

Create the directory path in the uploader root path.



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rake/contrib/ftptools.rb', line 103

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
	  puts "Creating Directory  #{current_dir}" if @verbose
	  @ftp.mkdir(current_dir) rescue nil
	end
  end
end

#upload_files(wildcard) ⇒ Object

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



118
119
120
121
122
# File 'lib/rake/contrib/ftptools.rb', line 118

def upload_files(wildcard)
  Dir[wildcard].each do |fn|
	upload(fn)
  end
end