Manage the uploading of files to an FTP account.
[RW] |
verbose |
Log uploads to standard output when true.
|
Create an uploader and pass it to the given block as up. When the
block is complete, close the uploader.
95: def connect(path, host, account, password)
96: up = self.new(path, host, account, password)
97: begin
98: yield(up)
99: ensure
100: up.close
101: end
102: end
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.
108: def initialize(path, host, account, password)
109: @created = Hash.new
110: @path = path
111: @ftp = Net::FTP.new(host, account, password)
112: makedirs(@path)
113: @ftp.chdir(@path)
114: end
139: def close
140: @ftp.close
141: end
Create the directory path in the uploader root path.
117: def makedirs(path)
118: route = []
119: File.split(path).each do |dir|
120: route << dir
121: current_dir = File.join(route)
122: if @created[current_dir].nil?
123: @created[current_dir] = true
124: puts "Creating Directory #{current_dir}" if @verbose
125: @ftp.mkdir(current_dir) rescue nil
126: end
127: end
128: end
Upload all files matching wildcard to the uploader’s root
path.
132: def upload_files(wildcard)
133: Dir[wildcard].each do |fn|
134: upload(fn)
135: end
136: end