1
# = Tools for FTP uploading.
3
# This file is still under development and is not released for general
11
####################################################################
12
# <b>Note:</b> <em> Not released for general use.</em>
14
attr_reader :name, :size, :owner, :group, :time
24
def initialize(path, entry)
26
@mode, line, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
28
@time = determine_time(d1, d2, d3)
32
File.join(@path, @name)
47
private # --------------------------------------------------------
52
result = 2*result + ((m[i]==?-) ? 0 : 1)
57
def determine_time(d1, d2, d3)
58
now = self.class.time.now
61
result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
63
result = Time.parse("#{d1} #{d2} #{now.year-1} #{d3}")
66
result = Time.parse("#{d1} #{d2} #{d3}")
69
# elements = ParseDate.parsedate("#{d1} #{d2} #{d3}")
71
# today = self.class.date.today
72
# if elements[1] > today.month
73
# elements[0] = today.year - 1
75
# elements[0] = today.year
78
# elements = elements.collect { |el| el.nil? ? 0 : el }
79
# Time.mktime(*elements[0,7])
83
####################################################################
84
# Manage the uploading of files to an FTP account.
87
# Log uploads to standard output when true.
88
attr_accessor :verbose
91
# Create an uploader and pass it to the given block as +up+.
92
# When the block is complete, close the uploader.
93
def connect(path, host, account, password)
94
up = self.new(path, host, account, password)
103
# Create an FTP uploader targetting the directory +path+ on +host+
104
# using the given account and password. +path+ will be the root
105
# path of the uploader.
106
def initialize(path, host, account, password)
109
@ftp = Net::FTP.new(host, account, password)
114
# Create the directory +path+ in the uploader root path.
117
File.split(path).each do |dir|
119
current_dir = File.join(route)
120
if @created[current_dir].nil?
121
@created[current_dir] = true
122
puts "Creating Directory #{current_dir}" if @verbose
123
@ftp.mkdir(current_dir) rescue nil
128
# Upload all files matching +wildcard+ to the uploader's root
130
def upload_files(wildcard)
131
Dir[wildcard].each do |fn|
136
# Close the uploader.
141
private # --------------------------------------------------------
143
# Upload a single file to the uploader's root path.
145
puts "Uploading #{file}" if @verbose
146
dir = File.dirname(file)
148
@ftp.putbinaryfile(file, file) unless File.directory?(file)