/
ftp.rb
39 lines (31 loc) · 892 Bytes
/
ftp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "net/ftp"
module PowerReviews
module Protocols
class Ftp < Base
# Returns true if the done file is missing
def done?
!client.nlst.include?(@config['done'])
end
# Delete the done file
def done!
client.delete(@config['done'])
end
# Do the copying of the zip file to the preferred destination
def copy_zip(to)
puts 'FTP getting file'
client.getbinaryfile(@config['zip'], to)
end
# do any cleanup necessary
def cleanup
@client.close
end
def client
return @client unless @client.nil?
puts "Connecting to #{@config['host']} as #{@config['username']}"
@client = Net::FTP.new(@config['host'])
@client.login(@config['username'], @config['password'])
@client
end
end
end
end