7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/ftp-ext.rb', line 7
def put_dir(opts = {})
options = {
:local => ".",
:remote => ".",
:verbose => false,
:erase => false,
:exclude => []
}.merge!(opts)
unless options[:preformatted]
options[:exclude].map! { |f| File.join(options[:local], f) }
options[:preformatted] = true
end
if !remote_file_exists?(options[:remote])
file_segments = options[:remote].split(File::SEPARATOR)
file_segments.length.times do |n|
fpath = File.join(file_segments[0..n])
unless remote_file_exists?(fpath) || fpath == ""
puts "mkdir #{fpath}" if options[:verbose] == true
mkdir(fpath)
end
end
else
options[:erase] ? (rmrf_dir(options[:remote], options[:verbose]); put_dir(options)) : sync_dir(options)
return
end
Dir.foreach(options[:local]) do |f|
local = File.join(options[:local], f)
remote = File.join(options[:remote], f)
(puts "excluding #{local}"; next) if options[:exclude].include?(local)
if File.file?(local)
puts "cp #{remote}" if options[:verbose] == true
File.binary?(local) ? putbinaryfile(local, remote) : puttextfile(local, remote)
elsif !f.match(/^\.+$/)
put_dir(options.merge({ :local => local, :remote => remote }))
end
end
end
|