Class: Dabcup::Storage::Driver::FTP
- Inherits:
-
Base
- Object
- Base
- Dabcup::Storage::Driver::FTP
show all
- Defined in:
- lib/dabcup/storage/driver/ftp.rb
Instance Attribute Summary
Attributes inherited from Base
#uri
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #protocol
Instance Method Details
#delete(file_name) ⇒ Object
26
27
28
29
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 26
def delete(file_name)
file_path = File.join(path, file_name)
ftp.delete(file_path)
end
|
#disconnect ⇒ Object
41
42
43
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 41
def disconnect
@ftp.close if @ftp
end
|
#ftp ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 31
def ftp
unless @ftp
@ftp = Net::FTP.new
@ftp.connect(host, port || 21)
@ftp.login(user, password)
mkdirs
end
@ftp
end
|
#get(remote_name, local_path) ⇒ Object
10
11
12
13
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 10
def get(remote_name, local_path)
remote_path = File.join(path, remote_name)
ftp.getbinaryfile(remote_path, local_path)
end
|
#list ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 15
def list
dumps = []
lines = ftp.list(path)
lines.collect do |str|
fields = str.split(' ')
next unless Dump.valid_name?(fields[8])
dumps << Dabcup::Storage::Dump.new(:name => fields[8], :size => fields[4].to_i)
end
dumps
end
|
#local? ⇒ Boolean
45
46
47
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 45
def local?
false
end
|
#mkdirs ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 49
def mkdirs
dirs = []
path = path
first_exception = nil
begin
ftp.nlst(path)
rescue Net::FTPTempError => ex
dirs << path
path = File.dirname(path)
first_exception = ex unless first_exception
if path == '.'
raise first_exception
else
retry
end
end
dirs.reverse.each do |dir|
ftp.mkdir(dir)
end
end
|
#put(local_path, remote_name) ⇒ Object
5
6
7
8
|
# File 'lib/dabcup/storage/driver/ftp.rb', line 5
def put(local_path, remote_name)
remote_path = File.join(path, remote_name)
ftp.putbinaryfile(local_path, remote_path)
end
|