Class: Rftp

Inherits:
Object
  • Object
show all
Defined in:
lib/rftp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Rftp

Returns a new instance of Rftp.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rftp.rb', line 115

def initialize(options)
  options.rftp_symbolize_keys
  
  begin
    self.connection = Net::FTP.new options[:host]
  rescue SocketError => socket_error
    raise "Unable to connect to #{options[:host]}. #{socket_error}"  
  end
  
  begin
    if options[:username] && options[:password]
      self.connection. options[:username], options[:password]
    else
      self.connection.
    end
  rescue Net::FTPPermError => error
    raise "Unable to login to #{options[:host]}. #{error}"
  end
  
  if options[:passive]
    self.connection.passive = true
  end
  
  self.root = self.connection.pwd
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



113
114
115
# File 'lib/rftp.rb', line 113

def connection
  @connection
end

#rootObject

Returns the value of attribute root.



113
114
115
# File 'lib/rftp.rb', line 113

def root
  @root
end

Instance Method Details

#[](num) ⇒ Object



153
154
155
# File 'lib/rftp.rb', line 153

def [](num)
  ls[num]
end

#collect(&block) ⇒ Object



147
148
149
150
151
# File 'lib/rftp.rb', line 147

def collect(&block)
  ls.collect do |file|
    yield file
  end
end

#each(&block) ⇒ Object



141
142
143
144
145
# File 'lib/rftp.rb', line 141

def each(&block)
  ls.each do |file|
    yield file
  end
end

#ls(path = ".") ⇒ Object



157
158
159
160
# File 'lib/rftp.rb', line 157

def ls(path = ".")
  self.connection.chdir path
  RftpDirectory.new(self.root, self, self.connection.ls("-T"))
end