net-sftp-backports 4.0.0.backports

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.
@@ -0,0 +1,68 @@
1
+ module Net
2
+ module SFTP
3
+ # A class for describing the current version of a library. The version
4
+ # consists of three parts: the +major+ number, the +minor+ number, and the
5
+ # +tiny+ (or +patch+) number.
6
+ #
7
+ # Two Version instances may be compared, so that you can test that a version
8
+ # of a library is what you require:
9
+ #
10
+ # require 'net/sftp/version'
11
+ #
12
+ # if Net::SFTP::Version::CURRENT < Net::SFTP::Version[2,1,0]
13
+ # abort "your software is too old!"
14
+ # end
15
+ class Version
16
+ include Comparable
17
+
18
+ # A convenience method for instantiating a new Version instance with the
19
+ # given +major+, +minor+, and +tiny+ components.
20
+ def self.[](major, minor, tiny, pre = nil)
21
+ new(major, minor, tiny, pre)
22
+ end
23
+
24
+ attr_reader :major, :minor, :tiny
25
+
26
+ # Create a new Version object with the given components.
27
+ def initialize(major, minor, tiny, pre = nil)
28
+ @major, @minor, @tiny, @pre = major, minor, tiny, pre
29
+ end
30
+
31
+ # Compare this version to the given +version+ object.
32
+ def <=>(version)
33
+ to_i <=> version.to_i
34
+ end
35
+
36
+ # Converts this version object to a string, where each of the three
37
+ # version components are joined by the '.' character. E.g., 2.0.0.
38
+ def to_s
39
+ @to_s ||= [@major, @minor, @tiny, @pre].compact.join(".")
40
+ end
41
+
42
+ # Converts this version to a canonical integer that may be compared
43
+ # against other version objects.
44
+ def to_i
45
+ @to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
46
+ end
47
+
48
+ # The major component of this version of the Net::SFTP library
49
+ MAJOR = 4
50
+
51
+ # The minor component of this version of the Net::SFTP library
52
+ MINOR = 0
53
+
54
+ # The tiny component of this version of the Net::SFTP library
55
+ TINY = 0
56
+
57
+ # The prerelease component of this version of the Net::SFTP library
58
+ # nil allowed
59
+ PRE = "backports"
60
+
61
+ # The current version of the Net::SFTP library as a Version instance
62
+ CURRENT = new(*[MAJOR, MINOR, TINY, PRE].compact)
63
+
64
+ # The current version of the Net::SFTP library as a String
65
+ STRING = CURRENT.to_s
66
+ end
67
+ end
68
+ end
data/lib/net/sftp.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'net/ssh'
2
+ require 'net/sftp/session'
3
+
4
+ module Net
5
+
6
+ # Net::SFTP is a pure-Ruby module for programmatically interacting with a
7
+ # remote host via the SFTP protocol (that's SFTP as in "Secure File Transfer
8
+ # Protocol" produced by the Secure Shell Working Group, not "Secure FTP"
9
+ # and certainly not "Simple FTP").
10
+ #
11
+ # See Net::SFTP#start for an introduction to the library. Also, see
12
+ # Net::SFTP::Session for further documentation.
13
+ module SFTP
14
+ # A convenience method for starting a standalone SFTP session. It will
15
+ # start up an SSH session using the given arguments (see the documentation
16
+ # for Net::SSH::Session for details), and will then start a new SFTP session
17
+ # with the SSH session. This will block until the new SFTP is fully open
18
+ # and initialized before returning it.
19
+ #
20
+ # sftp = Net::SFTP.start("localhost", "user")
21
+ # sftp.upload! "/local/file.tgz", "/remote/file.tgz"
22
+ #
23
+ # If a block is given, it will be passed to the SFTP session and will be
24
+ # called once the SFTP session is fully open and initialized. When the
25
+ # block terminates, the new SSH session will automatically be closed.
26
+ #
27
+ # Net::SFTP.start("localhost", "user") do |sftp|
28
+ # sftp.upload! "/local/file.tgz", "/remote/file.tgz"
29
+ # end
30
+ #
31
+ # Extra parameters can be passed:
32
+ # - The Net::SSH connection options (see Net::SSH for more information)
33
+ # - The Net::SFTP connection options (only :version is supported, to let you
34
+ # set the SFTP protocol version to be used)
35
+ def self.start(host, user, ssh_options={}, sftp_options={}, &block)
36
+ session = Net::SSH.start(host, user, ssh_options)
37
+ # We only use a single option here, but this leaves room for more later
38
+ # without breaking the external API.
39
+ version = sftp_options.fetch(:version, nil)
40
+ sftp = Net::SFTP::Session.new(session, version, &block).connect!
41
+
42
+ if block_given?
43
+ sftp.loop
44
+ session.close
45
+ return nil
46
+ end
47
+
48
+ sftp
49
+ rescue Object => anything
50
+ begin
51
+ session.shutdown!
52
+ rescue ::Exception
53
+ # swallow exceptions that occur while trying to shutdown
54
+ end
55
+
56
+ raise anything
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ class Net::SSH::Connection::Session
63
+ # A convenience method for starting up a new SFTP connection on the current
64
+ # SSH session. Blocks until the SFTP session is fully open, and then
65
+ # returns the SFTP session.
66
+ #
67
+ # Net::SSH.start("localhost", "user", :password => "password") do |ssh|
68
+ # ssh.sftp.upload!("/local/file.tgz", "/remote/file.tgz")
69
+ # ssh.exec! "cd /some/path && tar xf /remote/file.tgz && rm /remote/file.tgz"
70
+ # end
71
+ def sftp(wait=true)
72
+ @sftp ||= begin
73
+ sftp = Net::SFTP::Session.new(self)
74
+ sftp.connect! if wait
75
+ sftp
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDQDCCAiigAwIBAgIBATANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpuZXRz
3
+ c2gvREM9c29sdXRpb3VzL0RDPWNvbTAeFw0yMjA5MjIxMTUwMDJaFw0yMzA5MjIx
4
+ MTUwMDJaMCUxIzAhBgNVBAMMGm5ldHNzaC9EQz1zb2x1dGlvdXMvREM9Y29tMIIB
5
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxieE22fR/qmdPKUHyYTyUx2g
6
+ wskLwrCkxay+Tvc97ZZUOwf85LDDDPqhQaTWLvRwnIOMgQE2nBPzwalVclK6a+pW
7
+ x/18KDeZY15vm3Qn5p42b0wi9hUxOqPm3J2hdCLCcgtENgdX21nVzejn39WVqFJO
8
+ lntgSDNW5+kCS8QaRsmIbzj17GKKkrsw39kiQw7FhWfJFeTjddzoZiWwc59KA/Bx
9
+ fBbmDnsMLAtAtauMOxORrbx3EOY7sHku/kSrMg3FXFay7jc6BkbbUij+MjJ/k82l
10
+ 4o8o0YO4BAnya90xgEmgOG0LCCxRhuXQFnMDuDjK2XnUe0h4/6NCn94C+z9GsQID
11
+ AQABo3sweTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUBfKiwO2e
12
+ M4NEiRrVG793qEPLYyMwHwYDVR0RBBgwFoEUbmV0c3NoQHNvbHV0aW91cy5jb20w
13
+ HwYDVR0SBBgwFoEUbmV0c3NoQHNvbHV0aW91cy5jb20wDQYJKoZIhvcNAQELBQAD
14
+ ggEBABI2ORK5kzUL7uOF0EHI4ECMWxQMiN+pURyGp9u7DU0H8eSdZN52jbUGHzSB
15
+ j7bB6GpqElEWjOe0IbH3vR52IVXq2bOF4P4vFchGAb4OuzJD8aJmrC/SPLHbWBuV
16
+ 2GpbRQRJyYPWN6Rt/4EHOxoFnhXOBEB6CGIy0dt7YezycVbzqtHoiI2Qf/bIFJQZ
17
+ mpJAAUBkRiWksE7zrsE5DGK8kL2GVos7f8kdM71zT8p7VBwkMdY277T29TG2xD0D
18
+ 66Oev0C3/x89NXqCHkl1JElSzEFbOoxan16z7xNEf2MKcBKGhsYfzWVNyEtJm785
19
+ g+97rn/AuO6dcxJnW2qBGYQa7pQ=
20
+ -----END CERTIFICATE-----
data/net-sftp.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ require_relative 'lib/net/sftp/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "net-sftp-backports"
5
+ spec.version = Net::SFTP::Version::STRING
6
+ spec.authors = ["Jamis Buck", "Delano Mandelbaum", "Mikl\u{f3}s Fazekas"]
7
+ spec.email = ["net-ssh@solutious.com"]
8
+
9
+ if ENV['NET_SSH_BUILDGEM_SIGNED']
10
+ spec.cert_chain = ["net-sftp-public_cert.pem"]
11
+ spec.signing_key = "/mnt/gem/net-ssh-private_key.pem"
12
+ end
13
+
14
+ spec.summary = %q{A pure Ruby implementation of the SFTP client protocol.}
15
+ spec.description = %q{A pure Ruby implementation of the SFTP client protocol}
16
+ spec.homepage = "https://github.com/net-ssh/net-sftp"
17
+ spec.license = "MIT"
18
+ spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? :required_rubygems_version=
19
+
20
+ spec.extra_rdoc_files = [
21
+ "LICENSE.txt",
22
+ "README.rdoc"
23
+ ]
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ if spec.respond_to? :specification_version then
31
+ spec.specification_version = 3
32
+
33
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
34
+ spec.add_runtime_dependency(%q<net-ssh-backports>, [">= 6.0.0", "< 7.0.0"])
35
+ spec.add_development_dependency(%q<minitest>, [">= 5"])
36
+ spec.add_development_dependency(%q<mocha>, [">= 0"])
37
+ else
38
+ spec.add_dependency(%q<net-ssh>, [">= 5.0.0", "< 8.0.0"])
39
+ spec.add_dependency(%q<minitest>, [">= 5"])
40
+ spec.add_dependency(%q<mocha>, [">= 0"])
41
+ end
42
+ else
43
+ spec.add_dependency(%q<net-ssh>, [">= 5.0.0", "< 8.0.0"])
44
+ spec.add_dependency(%q<minitest>, [">= 5"])
45
+ spec.add_dependency(%q<test-unit>, [">= 0"])
46
+ spec.add_dependency(%q<mocha>, [">= 0"])
47
+ end
48
+ end