Class: ReplicateFtp
- Defined in:
- lib/hobix/publish/replicate.rb
Constant Summary
Constants inherited from Replicate
Instance Attribute Summary collapse
-
#ftp ⇒ Object
Returns the value of attribute ftp.
-
#host ⇒ Object
Returns the value of attribute host.
-
#passwd ⇒ Object
Returns the value of attribute passwd.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes inherited from Replicate
Instance Method Summary collapse
- #cp(src, tgt) ⇒ Object
- #directory?(d) ⇒ Boolean
-
#initialize(hash_src, hash_tgt) ⇒ ReplicateFtp
constructor
A new instance of ReplicateFtp.
- #login ⇒ Object
- #logout ⇒ Object
- #mkdir_p(tgt) ⇒ Object
Methods inherited from Replicate
#check_and_make_dirs, #copy, #copy_files, #get_dirs, #get_files
Constructor Details
#initialize(hash_src, hash_tgt) ⇒ ReplicateFtp
Returns a new instance of ReplicateFtp.
203 204 205 206 207 208 209 210 |
# File 'lib/hobix/publish/replicate.rb', line 203 def initialize(hash_src, hash_tgt) super(hash_src,hash_tgt) @user = hash_tgt['user'] @passwd = hash_tgt['passwd'] @host = hash_tgt['host'] end |
Instance Attribute Details
#ftp ⇒ Object
Returns the value of attribute ftp.
201 202 203 |
# File 'lib/hobix/publish/replicate.rb', line 201 def ftp @ftp end |
#host ⇒ Object
Returns the value of attribute host.
201 202 203 |
# File 'lib/hobix/publish/replicate.rb', line 201 def host @host end |
#passwd ⇒ Object
Returns the value of attribute passwd.
201 202 203 |
# File 'lib/hobix/publish/replicate.rb', line 201 def passwd @passwd end |
#user ⇒ Object
Returns the value of attribute user.
201 202 203 |
# File 'lib/hobix/publish/replicate.rb', line 201 def user @user end |
Instance Method Details
#cp(src, tgt) ⇒ Object
264 265 266 |
# File 'lib/hobix/publish/replicate.rb', line 264 def cp(src,tgt) ftp.putbinaryfile src, tgt end |
#directory?(d) ⇒ Boolean
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/hobix/publish/replicate.rb', line 221 def directory?(d) old_dir = ftp.pwd begin ftp.chdir d # If we successfully change to d, we could now return to orig dir # otherwise we're in the rescue section ... ftp.chdir(old_dir) return true rescue Net::FTPPermError if $!.to_s[0,3] == "550" # 550 : No such file or directory return false end raise Net::FTPPermError, $! end end |
#login ⇒ Object
212 213 214 215 |
# File 'lib/hobix/publish/replicate.rb', line 212 def login @ftp = Net::FTP.open(host) ftp.login user,passwd end |
#logout ⇒ Object
217 218 219 |
# File 'lib/hobix/publish/replicate.rb', line 217 def logout ftp.close end |
#mkdir_p(tgt) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/hobix/publish/replicate.rb', line 241 def mkdir_p(tgt) old_dir = ftp.pwd tgt.split(/\/+/).each do |dir| next if dir.size == 0 # Let's try to go down begin ftp.chdir(dir) # Ok .. So it was already existing .. rescue Net::FTPPermError if $!.to_s[0,3] == "550" # 550 : No such file or directory : let's create .. ftp.mkdir(dir) # and retry retry end raise Net::FTPPermError, $! end end ftp.chdir(old_dir) end |