Class: Sunnyside::SunnyFTP

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

Direct Known Subclasses

IncomingFiles, OutgoingFiles

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login = {}) ⇒ SunnyFTP

Returns a new instance of SunnyFTP.



17
18
19
20
21
22
# File 'lib/sunnyside/ftp.rb', line 17

def initialize( = {})
  @ftp      = Net::FTP.new([:site])
  @username = [:username]
  @password = [:password]
  @name     = [:provider]      
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



15
16
17
# File 'lib/sunnyside/ftp.rb', line 15

def directory
  @directory
end

#ftpObject (readonly)

Returns the value of attribute ftp.



15
16
17
# File 'lib/sunnyside/ftp.rb', line 15

def ftp
  @ftp
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/sunnyside/ftp.rb', line 15

def name
  @name
end

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/sunnyside/ftp.rb', line 15

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



15
16
17
# File 'lib/sunnyside/ftp.rb', line 15

def username
  @username
end

Instance Method Details

#check_for_new_filesObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sunnyside/ftp.rb', line 28

def check_for_new_files
  ftp.chdir("../outgoing")
  incoming = IncomingFiles.new(ftp, name)
  incoming.download_files

  ftp.chdir("../incoming")
  outgoing = OutgoingFiles.new(ftp, name)
  outgoing.upload_files

  puts "Exiting #{name}..."
  ftp.close
end

#log_onObject



24
25
26
# File 'lib/sunnyside/ftp.rb', line 24

def log_on
  ftp.(username, password)
end

#new_filesObject



42
43
44
# File 'lib/sunnyside/ftp.rb', line 42

def new_files
  files.map { |file| timestamp(file) + "-#{file}" }.select { |file| provider_folder.include?(timestamp(file)) }.size > 0
end