Class: ReplicateFtp

Inherits:
Replicate show all
Defined in:
lib/hobix/publish/replicate.rb

Constant Summary

Constants inherited from Replicate

Replicate::DIRFILE

Instance Attribute Summary collapse

Attributes inherited from Replicate

#items, #source, #target

Instance Method Summary collapse

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

#ftpObject

Returns the value of attribute ftp.



201
202
203
# File 'lib/hobix/publish/replicate.rb', line 201

def ftp
  @ftp
end

#hostObject

Returns the value of attribute host.



201
202
203
# File 'lib/hobix/publish/replicate.rb', line 201

def host
  @host
end

#passwdObject

Returns the value of attribute passwd.



201
202
203
# File 'lib/hobix/publish/replicate.rb', line 201

def passwd
  @passwd
end

#userObject

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

Returns:

  • (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

#loginObject



212
213
214
215
# File 'lib/hobix/publish/replicate.rb', line 212

def 
  @ftp = Net::FTP.open(host)
  ftp. user,passwd
end

#logoutObject



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