Class: RestFtpDaemon::Remote::RemoteFTP
Instance Attribute Summary collapse
Attributes inherited from RemoteBase
#job, #log_prefix
Instance Method Summary
collapse
Methods inherited from RemoteBase
#initialize
#dashboard_url, #exception_to_error, #format_bytes, #identifier, #underscore
Instance Attribute Details
#ftp ⇒ Object
10
11
12
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 10
def ftp
@ftp
end
|
Instance Method Details
#chdir_or_create(thedir, mkdir = true) ⇒ 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
88
89
90
91
92
93
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 62
def chdir_or_create thedir, mkdir = true
parent, current = split_path(thedir)
log_debug "chdir_or_create mkdir[#{mkdir}] dir[#{thedir}] parent[#{parent}] current[#{current}]"
begin
@ftp.chdir "/#{thedir}"
rescue Net::FTPPermError => _e
unless mkdir
log_debug " [#{thedir}] failed > no mkdir > over"
return false
end
log_debug " [#{thedir}] failed > chdir_or_create [#{parent}]"
chdir_or_create parent, mkdir
log_debug " [#{thedir}] failed > mkdir [#{current}]"
mkdir current
retry
else
return true
end
end
|
#close ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 124
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
132
133
134
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 132
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 "mkdir [#{directory}]"
@ftp.mkdir directory
rescue StandardError => ex
raise TargetPermissionError, ex.message
end
|
#prepare ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 12
def prepare
super
if @ftpes
prepare_ftpes
else
prepare_ftp
end
@ftp.passive = true
@ftp.debug_mode = @debug
log_debug "prepare chunk_size:#{format_bytes(JOB_FTP_CHUNKMB, "B")}"
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_fs
rescue Net::FTPPermError
log_debug "remove! [#{target.name}] not found"
else
log_debug "remove! [#{target.name}] removed"
end
|
#size_if_exists(target) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 36
def size_if_exists target
log_debug "size_if_exists [#{target.name}]"
size = @ftp.size target.path_fs
rescue Net::FTPPermError
return false
else
return size
end
|
#upload(source, target, use_temp_name = false, &callback) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/rest-ftp-daemon/remote/ftp.rb', line 95
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 "upload chdir [#{dest.dir_fs}]"
@ftp.chdir dest.dir_fs
log_debug "upload putbinaryfile [#{source.path_fs}] [#{dest.name}]"
@ftp.putbinaryfile source.path_fs, dest.name, JOB_FTP_CHUNKMB do |data|
yield data.bytesize, dest.name
end
if use_temp_name
log_debug "upload rename [#{dest.name}] > [#{target.name}]"
@ftp.rename dest.name, target.name
end
end
|