factor-connector-ftp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/factor/connector/ftp.rb +12 -8
  2. metadata +1 -1
@@ -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
- username = params['username']
7
- password = params['password']
8
- server = params['endpoint']
9
- path = params['path'] || '/'
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 endpoint (address) is required' unless 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(server) do |ftp|
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}@#{server}, please check credentials.", exception: ex
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor-connector-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: