factor-connector-ftp 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/factor/connector/ftp.rb +12 -8
- metadata +1 -1
data/lib/factor/connector/ftp.rb
CHANGED
@@ -1,28 +1,32 @@
|
|
1
1
|
require 'factor-connector-api'
|
2
2
|
require 'net/ftp'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
Factor::Connector.service 'ftp' do
|
5
6
|
action 'list' do |params|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
uri = URI("ftp://#{params['host']}")
|
8
|
+
host = uri.host
|
9
|
+
port = uri.port || 21
|
10
|
+
username = uri.user
|
11
|
+
password = uri.password
|
12
|
+
path = uri.path ? "/#{uri.path}" : '/'
|
10
13
|
|
11
|
-
fail 'Server
|
12
|
-
fail 'Path cant be empty' if path.empty?
|
14
|
+
fail 'Server host (address) is required' unless host
|
13
15
|
|
14
16
|
files = []
|
15
17
|
begin
|
16
|
-
Net::FTP.open(
|
18
|
+
Net::FTP.open(host) do |ftp|
|
17
19
|
if username && password
|
20
|
+
info "Logging in with username '#{username}'"
|
18
21
|
ftp.login(username, password)
|
19
22
|
else
|
23
|
+
info "Logging in without a username and password"
|
20
24
|
ftp.login
|
21
25
|
end
|
22
26
|
files = ftp.list(path)
|
23
27
|
end
|
24
28
|
rescue => ex
|
25
|
-
fail "Couldn't connect to the server #{username}@#{
|
29
|
+
fail "Couldn't connect to the server #{username}@#{host}, please check credentials.", exception: ex
|
26
30
|
end
|
27
31
|
|
28
32
|
action_callback files: files
|