Class: Monster::Remote::Wrappers::NetFTPHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/monster/remote/wrappers/net_ftp.rb

Overview

NetFTP

Instance Method Summary collapse

Constructor Details

#initialize(ftp) ⇒ NetFTPHandler

Returns a new instance of NetFTPHandler.



28
29
30
# File 'lib/monster/remote/wrappers/net_ftp.rb', line 28

def initialize(ftp)
  @ftp = ftp
end

Instance Method Details

#copy_file(from, to) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/monster/remote/wrappers/net_ftp.rb', line 62

def copy_file(from, to)
  if (dirs = dirs_in_path(to)).size > 1
    file = dirs.pop
    create_dir(dirs.join("/"))

    pwd = @ftp.pwd
    dirs.each { |dir| @ftp.chdir(dir) }
    @ftp.putbinaryfile(from, file)
    @ftp.chdir(pwd)
  else
    @ftp.putbinaryfile(from, to)
  end
end

#create_dir(dir) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/monster/remote/wrappers/net_ftp.rb', line 32

def create_dir(dir)
  pwd = @ftp.pwd

  dirs = dirs_in_path(dir)
  root_dir_name = dirs.shift

  create_and_chdir(root_dir_name)

  if dirs.size > 0
    dirs.each do |dir|
      create_and_chdir(dir)
    end
  end

  @ftp.chdir(pwd)
end

#remove_dir(dir) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/monster/remote/wrappers/net_ftp.rb', line 49

def remove_dir(dir)
  pwd = @ftp.pwd
  dirs = dirs_in_path(dir)
  final_dir = dirs.pop
  dirs.each { |dir| @ftp.chdir(dir) }
  empty_and_remove_dir(final_dir)
  while(final_dir = dirs.pop)
    @ftp.chdir("..")
    empty_and_remove_dir(final_dir)
  end
  @ftp.chdir(pwd)
end

#remove_file(file) ⇒ Object



76
77
78
# File 'lib/monster/remote/wrappers/net_ftp.rb', line 76

def remove_file(file)
  @ftp.delete(file)
end