Class: Libelule::Client

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, user, password) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
# File 'lib/libelule.rb', line 13

def initialize(host, user, password)
  @host = host
  @user = user
  @password = password
  @ftp_client = Net::FTP
end

Class Attribute Details

.silence_log_messagesObject

Returns the value of attribute silence_log_messages.



7
8
9
# File 'lib/libelule.rb', line 7

def silence_log_messages
  @silence_log_messages
end

Instance Attribute Details

#ftp_clientObject

Returns the value of attribute ftp_client.



11
12
13
# File 'lib/libelule.rb', line 11

def ftp_client
  @ftp_client
end

Instance Method Details

#clean_up(target_dir, options) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/libelule.rb', line 41

def clean_up(target_dir, options)
  suffix_to_keep = options[:suffix_to_keep]
  dry_run = options[:dry_run]
  raise ArgumentError, 'please provide a suffix to keep' unless /[A-Z]/ =~ suffix_to_keep
  ftp.(@user, @password)
  clean_up_folder(target_dir, suffix_to_keep, dry_run)
end

#clean_up_with_manifest(target_dir, manifest, options = {}) ⇒ Object



49
50
51
52
53
# File 'lib/libelule.rb', line 49

def clean_up_with_manifest(target_dir, manifest, options = {})
  ftp.(@user, @password)
  dry_run = options[:dry_run]
  clean_up_folder_with_manifest(target_dir, manifest, dry_run)
end

#ftpObject



20
21
22
23
24
25
26
# File 'lib/libelule.rb', line 20

def ftp
  if @ftp.nil? || @ftp.closed?
    @ftp = ftp_client.send(:new, @host)
    @ftp.passive = true
  end
  @ftp
end

#one_way_sync_from_local_to_remote(local_dir, remote_dir) ⇒ Object



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

def one_way_sync_from_local_to_remote(local_dir, remote_dir)
  begin
    ftp.(@user, @password)
    log "logged in, start syncing..."
    sync_folder(local_dir, remote_dir)
    log "sync finished"
    return true
  rescue Net::FTPPermError => e
    log "Failed: #{e.message}"
    return false
  end
end