xftp 0.2.0.pre.alpha → 0.2.1.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/xftp.rb +4 -32
- data/lib/xftp/client.rb +41 -0
- data/lib/xftp/errors.rb +1 -17
- data/lib/xftp/locale/en.yml +0 -3
- data/lib/xftp/locale/ru.yml +0 -3
- data/lib/xftp/session/ftp.rb +18 -3
- data/lib/xftp/session/sftp.rb +11 -4
- data/lib/xftp/version.rb +1 -1
- metadata +3 -23
- data/lib/xftp/validator/settings.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d82f44266494fe12bc8cf104135f043b3689e2c1
|
4
|
+
data.tar.gz: 5f5ccac9192ec65a366bc958ee625b31fc582602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b8ed8dffdf2737832b99cb3849f3bf3c1340da21eb5b49f3385cacae2d0ade0cf3cfdb2e6dc387323d7a11bb40e6768aa8d80ff4b2e963c750e30576d55bbd9
|
7
|
+
data.tar.gz: 49778fb1e45dc2468e49de0ef63e410b5fe180764f24953631afc5a73ffcef2b37d1ff359e18e8fdaa6e024edd261df828ef033d5436e1603bf162bf5c7203a2
|
data/README.md
CHANGED
@@ -23,9 +23,9 @@ XFTP.start('ftps://hostname', credentials: { login: 'login', password: 'pass' })
|
|
23
23
|
x.mkdir 'new-remote-dir'
|
24
24
|
x.rmdir 'dir-to-remove'
|
25
25
|
|
26
|
-
x.
|
27
|
-
|
28
|
-
x.move
|
26
|
+
x.each_file do |file|
|
27
|
+
x.download file
|
28
|
+
x.move file, to: File.join('remote-archive-path', file)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
```
|
data/lib/xftp.rb
CHANGED
@@ -4,21 +4,12 @@ require 'active_support/core_ext/hash'
|
|
4
4
|
require 'configuration'
|
5
5
|
require 'xftp/version'
|
6
6
|
require 'xftp/errors'
|
7
|
-
require 'xftp/
|
8
|
-
require 'xftp/session/ftp'
|
9
|
-
require 'xftp/session/sftp'
|
7
|
+
require 'xftp/client'
|
10
8
|
|
11
9
|
require_relative 'initializers/i18n'
|
12
10
|
|
13
|
-
#
|
11
|
+
# Interface unification for FTP/SFTP protocols
|
14
12
|
module XFTP
|
15
|
-
include Errors
|
16
|
-
|
17
|
-
SCHEME_ADAPTERS = {
|
18
|
-
ftp: XFTP::Session::FTP,
|
19
|
-
ftps: XFTP::Session::SFTP
|
20
|
-
}
|
21
|
-
|
22
13
|
# Config accessor
|
23
14
|
def self.config
|
24
15
|
@configuration ||= Configuration.new
|
@@ -30,10 +21,6 @@ module XFTP
|
|
30
21
|
yield config
|
31
22
|
end
|
32
23
|
|
33
|
-
def self.validator
|
34
|
-
@validator ||= Validator::Settings.new
|
35
|
-
end
|
36
|
-
|
37
24
|
# Initiates a new session
|
38
25
|
#
|
39
26
|
# @param [String] :url the remote host url
|
@@ -46,22 +33,7 @@ module XFTP
|
|
46
33
|
#
|
47
34
|
# @see Net::SSH
|
48
35
|
# @see Net::FTP
|
49
|
-
|
50
|
-
|
51
|
-
def self.start(url, settings = {}, &block)
|
52
|
-
uri = URI.parse(url)
|
53
|
-
validator.call!(uri, settings)
|
54
|
-
klass = adapter_class(uri.scheme)
|
55
|
-
session = klass.new(uri, settings.deep_dup)
|
56
|
-
session.start(&block)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# Detects a session adapter class
|
62
|
-
# @param [String, Symbol] scheme the uri scheme
|
63
|
-
# @return [Class] session adapter class
|
64
|
-
def self.adapter_class(scheme)
|
65
|
-
SCHEME_ADAPTERS[scheme.to_sym] || not_supported_protocol!(scheme)
|
36
|
+
def self.start(url, settings = {}, &callback)
|
37
|
+
Client.start(url, settings, &callback)
|
66
38
|
end
|
67
39
|
end
|
data/lib/xftp/client.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'xftp/session/ftp'
|
2
|
+
require 'xftp/session/sftp'
|
3
|
+
|
4
|
+
module XFTP
|
5
|
+
# The XFTP entry point
|
6
|
+
# @api private
|
7
|
+
class Client
|
8
|
+
SCHEME_ADAPTERS = {
|
9
|
+
ftp: XFTP::Session::FTP,
|
10
|
+
ftps: XFTP::Session::SFTP
|
11
|
+
}
|
12
|
+
|
13
|
+
def self.start(url, settings, &callback)
|
14
|
+
new(SCHEME_ADAPTERS).call(url, settings, &callback)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(scheme_adapters)
|
18
|
+
@scheme_adapters = scheme_adapters
|
19
|
+
end
|
20
|
+
|
21
|
+
# Initiates a new session
|
22
|
+
# @see XFTP::Validator::Settings
|
23
|
+
def call(url, settings, &block)
|
24
|
+
uri = URI.parse(url)
|
25
|
+
klass = adapter_class(uri.scheme)
|
26
|
+
session = klass.new(uri, settings.deep_dup)
|
27
|
+
session.start(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Detects a session adapter class
|
33
|
+
# @param [String, Symbol] scheme the uri scheme
|
34
|
+
# @return [Class] session adapter class
|
35
|
+
def adapter_class(scheme)
|
36
|
+
@scheme_adapters.fetch(scheme.to_sym) do
|
37
|
+
fail NotSupportedProtocol, "Not supported protocol '#{scheme}'"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/xftp/errors.rb
CHANGED
@@ -1,20 +1,4 @@
|
|
1
1
|
module XFTP
|
2
|
-
# Raises when the given
|
3
|
-
class InvalidArgument < ArgumentError; end
|
4
|
-
# Raises when required argument is missing or blank
|
5
|
-
class MissingArgument < ArgumentError; end
|
6
|
-
# Raise when the given protocol is not supported
|
2
|
+
# Raises when the given protocol is not supported
|
7
3
|
class NotSupportedProtocol < ArgumentError; end
|
8
|
-
|
9
|
-
# Shortcut method to fail
|
10
|
-
# with a localized error message
|
11
|
-
module Errors
|
12
|
-
def missing_setting!(setting)
|
13
|
-
fail MissingArgument, I18n.t('errors.missing_setting', key: setting)
|
14
|
-
end
|
15
|
-
|
16
|
-
def not_supported_protocol!(protocol)
|
17
|
-
fail NotSupportedProtocol, I18n.t('errors.not_supported_protocol', protocol: protocol)
|
18
|
-
end
|
19
|
-
end
|
20
4
|
end
|
data/lib/xftp/locale/en.yml
CHANGED
data/lib/xftp/locale/ru.yml
CHANGED
data/lib/xftp/session/ftp.rb
CHANGED
@@ -22,7 +22,7 @@ module XFTP
|
|
22
22
|
super
|
23
23
|
|
24
24
|
@ftp = Net::FTP.new
|
25
|
-
@port =
|
25
|
+
@port = settings.delete(:port) || uri.port || Net::FTP::FTP_PORT
|
26
26
|
@credentials[:login] ||= 'anonymous'
|
27
27
|
|
28
28
|
options = XFTP.config.ftp.deep_merge(@settings)
|
@@ -34,6 +34,22 @@ module XFTP
|
|
34
34
|
entries.include? dirname
|
35
35
|
end
|
36
36
|
|
37
|
+
# @return [Boolean] `true` if the argument refers to
|
38
|
+
# a directory on the remote host
|
39
|
+
def directory?(path)
|
40
|
+
chdir path
|
41
|
+
chdir '..'
|
42
|
+
true
|
43
|
+
rescue
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Boolean] `true` if the argument refers to
|
48
|
+
# a file on the remote host
|
49
|
+
def file?(path)
|
50
|
+
!directory?(path)
|
51
|
+
end
|
52
|
+
|
37
53
|
# Renames (moves) a file on the server
|
38
54
|
# @param [String] from the path to move from
|
39
55
|
# @param [String] to the new path to move to
|
@@ -63,8 +79,7 @@ module XFTP
|
|
63
79
|
|
64
80
|
# @return [Array<String>] an array of filenames in the remote directory
|
65
81
|
def files
|
66
|
-
|
67
|
-
entries '*.*'
|
82
|
+
entries.select { |entry| file? entry }
|
68
83
|
end
|
69
84
|
|
70
85
|
# @param [String] pattern the wildcard search pattern
|
data/lib/xftp/session/sftp.rb
CHANGED
@@ -19,7 +19,7 @@ module XFTP
|
|
19
19
|
def initialize(uri, settings = {})
|
20
20
|
super
|
21
21
|
@path = Pathname '.'
|
22
|
-
@settings
|
22
|
+
@settings[:password] = @credentials[:password]
|
23
23
|
@ssh_options = XFTP.config.ssh.deep_merge(@settings)
|
24
24
|
end
|
25
25
|
|
@@ -44,9 +44,16 @@ module XFTP
|
|
44
44
|
entries.include? filename
|
45
45
|
end
|
46
46
|
|
47
|
-
# @return [Boolean] `true` if the argument refers to
|
48
|
-
|
49
|
-
|
47
|
+
# @return [Boolean] `true` if the argument refers to
|
48
|
+
# a directory on the remote host
|
49
|
+
def directory?(path)
|
50
|
+
@sftp.file.directory? remote_path(path)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Boolean] `true` if the argument refers to
|
54
|
+
# a file on the remote host
|
55
|
+
def file?(path)
|
56
|
+
!directory?(path)
|
50
57
|
end
|
51
58
|
|
52
59
|
# Removes the remote directory
|
data/lib/xftp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1.pre.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliy Yorkin
|
@@ -112,26 +112,6 @@ dependencies:
|
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: 0.9.2
|
115
|
-
- !ruby/object:Gem::Dependency
|
116
|
-
name: fake_ftp
|
117
|
-
requirement: !ruby/object:Gem::Requirement
|
118
|
-
requirements:
|
119
|
-
- - "~>"
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version: '0.1'
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.1.1
|
125
|
-
type: :development
|
126
|
-
prerelease: false
|
127
|
-
version_requirements: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.1'
|
132
|
-
- - ">="
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: 0.1.1
|
135
115
|
- !ruby/object:Gem::Dependency
|
136
116
|
name: i18n
|
137
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +185,7 @@ files:
|
|
205
185
|
- lib/configuration.rb
|
206
186
|
- lib/initializers/i18n.rb
|
207
187
|
- lib/xftp.rb
|
188
|
+
- lib/xftp/client.rb
|
208
189
|
- lib/xftp/dsl/block_evaluator.rb
|
209
190
|
- lib/xftp/errors.rb
|
210
191
|
- lib/xftp/locale/en.yml
|
@@ -213,7 +194,6 @@ files:
|
|
213
194
|
- lib/xftp/session/base.rb
|
214
195
|
- lib/xftp/session/ftp.rb
|
215
196
|
- lib/xftp/session/sftp.rb
|
216
|
-
- lib/xftp/validator/settings.rb
|
217
197
|
- lib/xftp/version.rb
|
218
198
|
homepage: https://github.com/vyorkin/xftp
|
219
199
|
licenses:
|
@@ -238,6 +218,6 @@ rubyforge_project:
|
|
238
218
|
rubygems_version: 2.2.2
|
239
219
|
signing_key:
|
240
220
|
specification_version: 4
|
241
|
-
summary: xftp-0.2.
|
221
|
+
summary: xftp-0.2.1-alpha
|
242
222
|
test_files: []
|
243
223
|
has_rdoc:
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module XFTP
|
2
|
-
module Validator
|
3
|
-
# Connection settings validator
|
4
|
-
# @api private
|
5
|
-
class Settings
|
6
|
-
include Errors
|
7
|
-
|
8
|
-
# Validates the given connection settings
|
9
|
-
# @param [URI] uri the remote uri
|
10
|
-
# @param [Hash] settings the session connection settings
|
11
|
-
# @raise [XFTP::MissingArgument] if some of the required settings are missing
|
12
|
-
def call!(uri, settings)
|
13
|
-
validate_credentials!(settings[:credentials]) if uri.scheme == 'ftps'
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def validate_credentials!(credentials)
|
19
|
-
missing_setting!(:credentials) unless credentials.present?
|
20
|
-
missing_setting!(:login) unless credentials[:login].present?
|
21
|
-
missing_setting!(:password) unless credentials[:password].present?
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|