Class: RestFtpDaemon::RemoteFTP
- Inherits:
-
Remote
- Object
- Remote
- RestFtpDaemon::RemoteFTP
show all
- Defined in:
- lib/rest-ftp-daemon/remote_ftp.rb
Instance Attribute Summary collapse
Attributes inherited from Remote
#job, #log_prefix, #logger
Instance Method Summary
collapse
Methods inherited from Remote
#initialize
Instance Attribute Details
#ftp ⇒ Object
9
10
11
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 9
def ftp
@ftp
end
|
Instance Method Details
#chdir_or_create(directory, mkdir = false) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 62
def chdir_or_create directory, mkdir = false
log_debug "RemoteFTP.chdir_or_create mkdir[#{mkdir}] dir[#{directory}]"
parent, current = (directory)
begin
@ftp.chdir "/#{directory}"
rescue Net::FTPPermError => _e
return false unless mkdir
chdir_or_create parent, mkdir
mkdir current
retry
else
return true
end
end
|
#close ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 117
def close
super
@ftp.close
end
|
#connect ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 28
def connect
super
@ftp.connect @target.host, @target.port
@ftp.login @target.user, @target.password
end
|
#connected? ⇒ Boolean
125
126
127
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 125
def connected?
!@ftp.welcome.nil?
end
|
#mkdir(directory) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 54
def mkdir directory
log_debug "RemoteFTP.mkdir [#{directory}]"
@ftp.mkdir directory
rescue StandardError => ex
raise TargetPermissionError, ex.message
end
|
#prepare ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 11
def prepare
if @ftpes
prepare_ftpes
else
prepare_ftp
end
@ftp.passive = true
@ftp.debug_mode = @debug
@chunk_size = DEFAULT_FTP_CHUNK.to_i * 1024
log_debug "RemoteFTP.prepare chunk_size:#{@chunk_size}"
end
|
#present?(target) ⇒ Boolean
36
37
38
39
40
41
42
43
44
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 36
def present? target
size = @ftp.size target.path
log_debug "RemoteFTP.present? [#{target.name}]"
rescue Net::FTPPermError
return false
else
return size
end
|
#remove!(target) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 46
def remove! target
@ftp.delete target.path
rescue Net::FTPPermError
log_debug "RemoteFTP.remove! [#{target.name}] not found"
else
log_debug "RemoteFTP.remove! [#{target.name}] removed"
end
|
#upload(source, target, use_temp_name = false, &callback) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/rest-ftp-daemon/remote_ftp.rb', line 89
def upload source, target, use_temp_name = false, &callback
raise RestFtpDaemon::AssertionFailed, "upload/ftp" if @ftp.nil?
dest = target.clone
if use_temp_name
dest.generate_temp_name!
end
log_debug "RemoteFTP.upload chdir [#{dest.dir}]"
@ftp.chdir "/#{dest.dir}"
log_debug "RemoteFTP.upload putbinaryfile [#{dest.name}]"
@ftp.putbinaryfile source.path, dest.name, @chunk_size do |data|
yield data.bytesize, dest.name
end
if use_temp_name
log_debug "RemoteFTP.upload rename [#{dest.name}] > [#{target.name}]"
@ftp.rename dest.name, target.name
end
end
|