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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +35 -0
- data/.gitignore +6 -0
- data/CHANGES.txt +67 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +19 -0
- data/Manifest +55 -0
- data/README.rdoc +118 -0
- data/Rakefile +53 -0
- data/lib/net/sftp/constants.rb +187 -0
- data/lib/net/sftp/errors.rb +39 -0
- data/lib/net/sftp/operations/dir.rb +93 -0
- data/lib/net/sftp/operations/download.rb +365 -0
- data/lib/net/sftp/operations/file.rb +198 -0
- data/lib/net/sftp/operations/file_factory.rb +60 -0
- data/lib/net/sftp/operations/upload.rb +395 -0
- data/lib/net/sftp/packet.rb +21 -0
- data/lib/net/sftp/protocol/01/attributes.rb +315 -0
- data/lib/net/sftp/protocol/01/base.rb +268 -0
- data/lib/net/sftp/protocol/01/name.rb +43 -0
- data/lib/net/sftp/protocol/02/base.rb +31 -0
- data/lib/net/sftp/protocol/03/base.rb +35 -0
- data/lib/net/sftp/protocol/04/attributes.rb +152 -0
- data/lib/net/sftp/protocol/04/base.rb +94 -0
- data/lib/net/sftp/protocol/04/name.rb +67 -0
- data/lib/net/sftp/protocol/05/base.rb +66 -0
- data/lib/net/sftp/protocol/06/attributes.rb +107 -0
- data/lib/net/sftp/protocol/06/base.rb +63 -0
- data/lib/net/sftp/protocol/base.rb +50 -0
- data/lib/net/sftp/protocol.rb +32 -0
- data/lib/net/sftp/request.rb +91 -0
- data/lib/net/sftp/response.rb +76 -0
- data/lib/net/sftp/session.rb +954 -0
- data/lib/net/sftp/version.rb +68 -0
- data/lib/net/sftp.rb +78 -0
- data/net-sftp-public_cert.pem +20 -0
- data/net-sftp.gemspec +48 -0
- data/setup.rb +1331 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d06f649000e5b6b2b99d1d7687823e13d26a5096946d328f6bc2b8c91a6f4f58
|
4
|
+
data.tar.gz: '094c9406cc40e516f1db5db40a7644ca5b97f119cb2197dfa00c57e0e9027602'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ba63089193e5900a47d1b4fb63eef6b356dc4c468c66b5c18f82c2e2445a108380f1bcc51e6a8f83fc7f47bfbeb470c02d90a785b1e2bbf373170cf4b8a5d50
|
7
|
+
data.tar.gz: 22052815baf86a9d676272c0d2b126f0ef8fa904c5d224ef5d06df188803bc7698f02f31faf1fb41d86192f7e440c51b671d80eb25f4cb794b17e14292778a21
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
runs-on: ubuntu-18.04
|
6
|
+
continue-on-error: ${{ matrix.flaky }}
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby-version: ["2.5", "2.6", "2.7", "3.0", "3.1", "truffleruby-22", "truffleruby-21"]
|
10
|
+
flaky: [false]
|
11
|
+
include:
|
12
|
+
- ruby-version: "ruby-head"
|
13
|
+
flaky: true
|
14
|
+
- ruby-version: "jruby-9.2"
|
15
|
+
flaky: true
|
16
|
+
- ruby-version: "jruby-9.3"
|
17
|
+
flaky: true
|
18
|
+
- ruby-version: "jruby-head"
|
19
|
+
flaky: true
|
20
|
+
- ruby-version: "truffleruby-head"
|
21
|
+
flaky: true
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v1
|
24
|
+
|
25
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
29
|
+
|
30
|
+
- name: Bundle install
|
31
|
+
run: |
|
32
|
+
gem install bundler
|
33
|
+
bundle install
|
34
|
+
- name: Run Tests
|
35
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/CHANGES.txt
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
=== 3.0.0
|
2
|
+
|
3
|
+
* Pass protocol version via Net::SFTP.start [#107]
|
4
|
+
* Net-ssh 6.0 support [#106]
|
5
|
+
|
6
|
+
=== 2.1.2 / 07 May 2013
|
7
|
+
|
8
|
+
* Fix fragmentation download failure [accardi]
|
9
|
+
|
10
|
+
=== 2.1.0 / 06 Feb 2013
|
11
|
+
|
12
|
+
* Added public cert. All gem releases are now signed. See INSTALL in readme.
|
13
|
+
* Remove self-require, it causes a warning in Ruby 1.9.2. [jbarnette]
|
14
|
+
* Allow for upload to use the filename of the local file by default [czarneckid]
|
15
|
+
* Properly handle receiving less data than requested. [thedarkone]
|
16
|
+
* Added option to create directory on directory upload [Pablo Merino]
|
17
|
+
* Remove a warnings in tests [kachick]
|
18
|
+
|
19
|
+
|
20
|
+
=== 2.0.5 / 19 Aug 2010
|
21
|
+
|
22
|
+
* Fixed missing StringIO exception in download! [Toby Bryans, Delano Mandelbaum]
|
23
|
+
|
24
|
+
|
25
|
+
=== 2.0.4 / 23 Nov 2009
|
26
|
+
|
27
|
+
* Fixed frozen string issue in StatusException.message [appoxy]
|
28
|
+
|
29
|
+
|
30
|
+
=== 2.0.3 / 17 Nov 2009
|
31
|
+
|
32
|
+
* Reference the correct Exception class when rescuing errors [Scott Tadman]
|
33
|
+
|
34
|
+
|
35
|
+
=== 2.0.2 / 1 Feb 2009
|
36
|
+
|
37
|
+
* Avoid using 'ensure' in Net::SFTP.start since it causes unfriendly behavior when exceptions are raised [Jamis Buck]
|
38
|
+
|
39
|
+
|
40
|
+
=== 2.0.1 / 29 May 2008
|
41
|
+
|
42
|
+
* Open files in binary mode to appease Windows [Jamis Buck]
|
43
|
+
|
44
|
+
|
45
|
+
=== 2.0.0 / 1 May 2008
|
46
|
+
|
47
|
+
* Make Net::SSH::Connection::Session#sftp accept an argument determining whether or not to block while the SFTP subsystem initializes (defaults to true) [Jamis Buck]
|
48
|
+
|
49
|
+
* Allow Session#connect to be useful even in the open/opening states by invoking or queuing the callback block [Jamis Buck]
|
50
|
+
|
51
|
+
* Allow custom properties to be set on upload/download initiation via the :properties option [Jamis Buck]
|
52
|
+
|
53
|
+
* Custom properties on Download instances [Jamis Buck]
|
54
|
+
|
55
|
+
* Add #abort! method to Upload and Download operations [Jamis Buck]
|
56
|
+
|
57
|
+
* More complete support for file-type detection in protocol versions 1-3 [Jamis Buck]
|
58
|
+
|
59
|
+
|
60
|
+
=== 2.0 Preview Release 2 (1.99.1) / 10 Apr 2008
|
61
|
+
|
62
|
+
* Custom properties on Upload instances [Jamis Buck]
|
63
|
+
|
64
|
+
|
65
|
+
=== 2.0 Preview Release 1 (1.99.0) / 22 Mar 2008
|
66
|
+
|
67
|
+
* Rewritten! (Never, ever, do this at home.) New and improved API.
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in mygem.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# TODO: add to gemspec
|
7
|
+
gem "bundler", "~> 2.1"
|
8
|
+
gem "rake", "~> 12.0"
|
9
|
+
|
10
|
+
gem 'byebug', group: %i[development test] if !Gem.win_platform? && RUBY_ENGINE == "ruby"
|
11
|
+
|
12
|
+
if ENV["CI"]
|
13
|
+
gem 'codecov', require: false, group: :test
|
14
|
+
gem 'simplecov', require: false, group: :test
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright © 2008 Jamis Buck
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the ‘Software’), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
CHANGELOG.rdoc
|
2
|
+
lib/net/sftp/constants.rb
|
3
|
+
lib/net/sftp/errors.rb
|
4
|
+
lib/net/sftp/operations/dir.rb
|
5
|
+
lib/net/sftp/operations/download.rb
|
6
|
+
lib/net/sftp/operations/file.rb
|
7
|
+
lib/net/sftp/operations/file_factory.rb
|
8
|
+
lib/net/sftp/operations/upload.rb
|
9
|
+
lib/net/sftp/packet.rb
|
10
|
+
lib/net/sftp/protocol/01/attributes.rb
|
11
|
+
lib/net/sftp/protocol/01/base.rb
|
12
|
+
lib/net/sftp/protocol/01/name.rb
|
13
|
+
lib/net/sftp/protocol/02/base.rb
|
14
|
+
lib/net/sftp/protocol/03/base.rb
|
15
|
+
lib/net/sftp/protocol/04/attributes.rb
|
16
|
+
lib/net/sftp/protocol/04/base.rb
|
17
|
+
lib/net/sftp/protocol/04/name.rb
|
18
|
+
lib/net/sftp/protocol/05/base.rb
|
19
|
+
lib/net/sftp/protocol/06/attributes.rb
|
20
|
+
lib/net/sftp/protocol/06/base.rb
|
21
|
+
lib/net/sftp/protocol/base.rb
|
22
|
+
lib/net/sftp/protocol.rb
|
23
|
+
lib/net/sftp/request.rb
|
24
|
+
lib/net/sftp/response.rb
|
25
|
+
lib/net/sftp/session.rb
|
26
|
+
lib/net/sftp/version.rb
|
27
|
+
lib/net/sftp.rb
|
28
|
+
Rakefile
|
29
|
+
README.rdoc
|
30
|
+
setup.rb
|
31
|
+
test/common.rb
|
32
|
+
test/protocol/01/test_attributes.rb
|
33
|
+
test/protocol/01/test_base.rb
|
34
|
+
test/protocol/01/test_name.rb
|
35
|
+
test/protocol/02/test_base.rb
|
36
|
+
test/protocol/03/test_base.rb
|
37
|
+
test/protocol/04/test_attributes.rb
|
38
|
+
test/protocol/04/test_base.rb
|
39
|
+
test/protocol/04/test_name.rb
|
40
|
+
test/protocol/05/test_base.rb
|
41
|
+
test/protocol/06/test_attributes.rb
|
42
|
+
test/protocol/06/test_base.rb
|
43
|
+
test/protocol/test_base.rb
|
44
|
+
test/test_all.rb
|
45
|
+
test/test_dir.rb
|
46
|
+
test/test_download.rb
|
47
|
+
test/test_file.rb
|
48
|
+
test/test_file_factory.rb
|
49
|
+
test/test_packet.rb
|
50
|
+
test/test_protocol.rb
|
51
|
+
test/test_request.rb
|
52
|
+
test/test_response.rb
|
53
|
+
test/test_session.rb
|
54
|
+
test/test_upload.rb
|
55
|
+
Manifest
|
data/README.rdoc
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
= Net::SFTP
|
2
|
+
|
3
|
+
<em><b>Please note: this project is in maintenance mode. It is not under active development but pull requests are very much welcome. Just be sure to include tests! -- delano</b></em>
|
4
|
+
|
5
|
+
|
6
|
+
* Docs: http://net-ssh.github.io/net-sftp
|
7
|
+
* Issues: https://github.com/net-ssh/net-sftp/issues
|
8
|
+
* Codes: https://github.com/net-ssh/net-sftp
|
9
|
+
* Email: net-ssh@solutious.com
|
10
|
+
|
11
|
+
<em>As of v2.1.0, all gem releases are signed. See INSTALL.</em>
|
12
|
+
|
13
|
+
|
14
|
+
== DESCRIPTION:
|
15
|
+
|
16
|
+
Net::SFTP is a pure-Ruby implementation of the SFTP protocol (specifically, versions 1 through 6 of the SFTP protocol). Note that this is the "Secure File Transfer Protocol", typically run over an SSH connection, and has nothing to do with the FTP protocol.
|
17
|
+
|
18
|
+
== FEATURES/PROBLEMS:
|
19
|
+
|
20
|
+
* Transfer files or even entire directory trees to or from a remote host via SFTP
|
21
|
+
* Completely supports all six protocol versions
|
22
|
+
* Asynchronous and synchronous operation
|
23
|
+
* Read and write files using an IO-like interface
|
24
|
+
|
25
|
+
== SYNOPSIS:
|
26
|
+
|
27
|
+
In a nutshell:
|
28
|
+
|
29
|
+
require 'net/sftp'
|
30
|
+
|
31
|
+
Net::SFTP.start('host', 'username', :password => 'password') do |sftp|
|
32
|
+
# upload a file or directory to the remote host
|
33
|
+
sftp.upload!("/path/to/local", "/path/to/remote")
|
34
|
+
|
35
|
+
# download a file or directory from the remote host
|
36
|
+
sftp.download!("/path/to/remote", "/path/to/local")
|
37
|
+
|
38
|
+
# grab data off the remote host directly to a buffer
|
39
|
+
data = sftp.download!("/path/to/remote")
|
40
|
+
|
41
|
+
# open and write to a pseudo-IO for a remote file
|
42
|
+
sftp.file.open("/path/to/remote", "w") do |f|
|
43
|
+
f.puts "Hello, world!\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
# open and read from a pseudo-IO for a remote file
|
47
|
+
sftp.file.open("/path/to/remote", "r") do |f|
|
48
|
+
puts f.gets
|
49
|
+
end
|
50
|
+
|
51
|
+
# create a directory
|
52
|
+
sftp.mkdir! "/path/to/directory"
|
53
|
+
|
54
|
+
# list the entries in a directory
|
55
|
+
sftp.dir.foreach("/path/to/directory") do |entry|
|
56
|
+
puts entry.longname
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
For the full documentation, start with Net::SFTP::Session. Also see Net::SFTP::Operations::Upload, Net::SFTP::Operations::Download, Net::SFTP::Operations::FileFactory, Net::SFTP::Operations::File, and Net::SFTP::Operations::Dir.
|
61
|
+
|
62
|
+
== REQUIREMENTS:
|
63
|
+
|
64
|
+
* Net::SSH 2
|
65
|
+
|
66
|
+
If you wish to run the tests, you'll need:
|
67
|
+
|
68
|
+
* Echoe (if you want to use the Rakefile)
|
69
|
+
* Mocha
|
70
|
+
|
71
|
+
== INSTALL:
|
72
|
+
|
73
|
+
* gem install net-sftp (might need sudo privileges)
|
74
|
+
|
75
|
+
However, in order to be sure the code you're installing hasn't been tampered with, it's recommended that you verify the signature[http://docs.rubygems.org/read/chapter/21]. To do this, you need to add my public key as a trusted certificate (you only need to do this once):
|
76
|
+
|
77
|
+
# Add the public key as a trusted certificate
|
78
|
+
# (You only need to do this once)
|
79
|
+
$ curl -O https://raw.githubusercontent.com/net-ssh/net-sftp/master/net-sftp-public_cert.pem
|
80
|
+
$ gem cert --add net-sftp-public_cert.pem
|
81
|
+
|
82
|
+
Then, when install the gem, do so with high security:
|
83
|
+
|
84
|
+
$ gem install net-sftp -P HighSecurity
|
85
|
+
|
86
|
+
If you don't add the public key, you'll see an error like "Couldn't verify data signature". If you're still having trouble let me know and I'll give you a hand.
|
87
|
+
|
88
|
+
Or, if you prefer to do it the hard way (sans Rubygems):
|
89
|
+
|
90
|
+
* tar xzf net-ssh-*.tgz
|
91
|
+
* cd net-ssh-*
|
92
|
+
* ruby setup.rb config
|
93
|
+
* ruby setup.rb install (might need sudo privileges)
|
94
|
+
|
95
|
+
== LICENSE:
|
96
|
+
|
97
|
+
(The MIT License)
|
98
|
+
|
99
|
+
Copyright (c) 2008 Jamis Buck <jamis@37signals.com>
|
100
|
+
|
101
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
102
|
+
a copy of this software and associated documentation files (the
|
103
|
+
'Software'), to deal in the Software without restriction, including
|
104
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
105
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
106
|
+
permit persons to whom the Software is furnished to do so, subject to
|
107
|
+
the following conditions:
|
108
|
+
|
109
|
+
The above copyright notice and this permission notice shall be
|
110
|
+
included in all copies or substantial portions of the Software.
|
111
|
+
|
112
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
113
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
114
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
115
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
116
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
117
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
118
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rake"
|
3
|
+
require "rake/clean"
|
4
|
+
require "rdoc/task"
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
|
7
|
+
desc "When releasing make sure NET_SSH_BUILDGEM_SIGNED is set"
|
8
|
+
task :check_NET_SSH_BUILDGEM_SIGNED do
|
9
|
+
raise "NET_SSH_BUILDGEM_SIGNED should be set to release" unless ENV['NET_SSH_BUILDGEM_SIGNED']
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::Task[:release].enhance [:check_NET_SSH_BUILDGEM_SIGNED]
|
13
|
+
Rake::Task[:release].prerequisites.unshift(:check_NET_SSH_BUILDGEM_SIGNED)
|
14
|
+
|
15
|
+
task :default => ["build"]
|
16
|
+
CLEAN.include [ 'pkg', 'rdoc' ]
|
17
|
+
name = "net-sftp"
|
18
|
+
|
19
|
+
require_relative "lib/net/sftp/version"
|
20
|
+
version = Net::SFTP::Version::CURRENT
|
21
|
+
|
22
|
+
namespace :cert do
|
23
|
+
desc "Update public cert from private - only run if public is expired"
|
24
|
+
task :update_public_when_expired do
|
25
|
+
require 'openssl'
|
26
|
+
require 'time'
|
27
|
+
raw = File.read "net-sftp-public_cert.pem"
|
28
|
+
certificate = OpenSSL::X509::Certificate.new raw
|
29
|
+
raise Exception, "Not yet expired: #{certificate.not_after}" unless certificate.not_after < Time.now
|
30
|
+
sh "gem cert --build netssh@solutious.com --days 365*5 --private-key /mnt/gem/net-ssh-private_key.pem"
|
31
|
+
sh "mv gem-public_cert.pem net-sftp-public_cert.pem"
|
32
|
+
sh "gem cert --add net-sftp-public_cert.pem"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rake/testtask'
|
37
|
+
Rake::TestTask.new do |t|
|
38
|
+
t.libs = ["lib", "test"]
|
39
|
+
end
|
40
|
+
|
41
|
+
extra_files = %w[LICENSE.txt THANKS.txt CHANGES.txt ]
|
42
|
+
RDoc::Task.new do |rdoc|
|
43
|
+
rdoc.rdoc_dir = "rdoc"
|
44
|
+
rdoc.title = "#{name} #{version}"
|
45
|
+
rdoc.generator = 'hanna' # gem install hanna-nouveau
|
46
|
+
rdoc.main = 'README.rdoc'
|
47
|
+
rdoc.rdoc_files.include("README*")
|
48
|
+
rdoc.rdoc_files.include("bin/*.rb")
|
49
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
50
|
+
extra_files.each { |file|
|
51
|
+
rdoc.rdoc_files.include(file) if File.exist?(file)
|
52
|
+
}
|
53
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module Net module SFTP
|
2
|
+
|
3
|
+
# The packet types and other general constants used by the SFTP protocol.
|
4
|
+
# See the specification for the SFTP protocol for a full discussion of their
|
5
|
+
# meaning and usage.
|
6
|
+
module Constants
|
7
|
+
|
8
|
+
# The various packet types supported by SFTP protocol versions 1 through 6.
|
9
|
+
# The FXP_EXTENDED and FXP_EXTENDED_REPLY packet types are not currently
|
10
|
+
# understood by Net::SFTP.
|
11
|
+
module PacketTypes
|
12
|
+
FXP_INIT = 1
|
13
|
+
FXP_VERSION = 2
|
14
|
+
|
15
|
+
FXP_OPEN = 3
|
16
|
+
FXP_CLOSE = 4
|
17
|
+
FXP_READ = 5
|
18
|
+
FXP_WRITE = 6
|
19
|
+
FXP_LSTAT = 7
|
20
|
+
FXP_FSTAT = 8
|
21
|
+
FXP_SETSTAT = 9
|
22
|
+
FXP_FSETSTAT = 10
|
23
|
+
FXP_OPENDIR = 11
|
24
|
+
FXP_READDIR = 12
|
25
|
+
FXP_REMOVE = 13
|
26
|
+
FXP_MKDIR = 14
|
27
|
+
FXP_RMDIR = 15
|
28
|
+
FXP_REALPATH = 16
|
29
|
+
FXP_STAT = 17
|
30
|
+
FXP_RENAME = 18
|
31
|
+
FXP_READLINK = 19
|
32
|
+
FXP_SYMLINK = 20
|
33
|
+
FXP_LINK = 21
|
34
|
+
FXP_BLOCK = 22
|
35
|
+
FXP_UNBLOCK = 23
|
36
|
+
|
37
|
+
FXP_STATUS = 101
|
38
|
+
FXP_HANDLE = 102
|
39
|
+
FXP_DATA = 103
|
40
|
+
FXP_NAME = 104
|
41
|
+
FXP_ATTRS = 105
|
42
|
+
|
43
|
+
FXP_EXTENDED = 200
|
44
|
+
FXP_EXTENDED_REPLY = 201
|
45
|
+
end
|
46
|
+
|
47
|
+
# Beginning in version 5 of the protocol, Net::SFTP::Session#rename accepts
|
48
|
+
# an optional +flags+ argument that must be either 0 or a combination of
|
49
|
+
# these constants.
|
50
|
+
module RenameFlags
|
51
|
+
OVERWRITE = 0x00000001
|
52
|
+
ATOMIC = 0x00000002
|
53
|
+
NATIVE = 0x00000004
|
54
|
+
end
|
55
|
+
|
56
|
+
# When an FXP_STATUS packet is received from the server, the +code+ will
|
57
|
+
# be one of the following constants.
|
58
|
+
module StatusCodes
|
59
|
+
FX_OK = 0
|
60
|
+
FX_EOF = 1
|
61
|
+
FX_NO_SUCH_FILE = 2
|
62
|
+
FX_PERMISSION_DENIED = 3
|
63
|
+
FX_FAILURE = 4
|
64
|
+
FX_BAD_MESSAGE = 5
|
65
|
+
FX_NO_CONNECTION = 6
|
66
|
+
FX_CONNECTION_LOST = 7
|
67
|
+
FX_OP_UNSUPPORTED = 8
|
68
|
+
FX_INVALID_HANDLE = 9
|
69
|
+
FX_NO_SUCH_PATH = 10
|
70
|
+
FX_FILE_ALREADY_EXISTS = 11
|
71
|
+
FX_WRITE_PROTECT = 12
|
72
|
+
FX_NO_MEDIA = 13
|
73
|
+
FX_NO_SPACE_ON_FILESYSTEM = 14
|
74
|
+
FX_QUOTA_EXCEEDED = 15
|
75
|
+
FX_UNKNOWN_PRINCIPLE = 16
|
76
|
+
FX_LOCK_CONFlICT = 17
|
77
|
+
FX_DIR_NOT_EMPTY = 18
|
78
|
+
FX_NOT_A_DIRECTORY = 19
|
79
|
+
FX_INVALID_FILENAME = 20
|
80
|
+
FX_LINK_LOOP = 21
|
81
|
+
end
|
82
|
+
|
83
|
+
# The Net::SFTP::Session#open operation is one of the worst casualties of
|
84
|
+
# the revisions between SFTP protocol versions. The flags change considerably
|
85
|
+
# between version 1 and version 6. Net::SFTP tries to shield programmers
|
86
|
+
# from the differences, so you'll almost never need to use these flags
|
87
|
+
# directly, but if you ever need to specify some flag that isn't exposed
|
88
|
+
# by the higher-level API, these are the ones that are available to you.
|
89
|
+
module OpenFlags
|
90
|
+
# These are the flags that are understood by versions 1-4 of the the
|
91
|
+
# open operation.
|
92
|
+
module FV1
|
93
|
+
READ = 0x00000001
|
94
|
+
WRITE = 0x00000002
|
95
|
+
APPEND = 0x00000004
|
96
|
+
CREAT = 0x00000008
|
97
|
+
TRUNC = 0x00000010
|
98
|
+
EXCL = 0x00000020
|
99
|
+
end
|
100
|
+
|
101
|
+
# Version 5 of the open operation totally discarded the flags understood
|
102
|
+
# by versions 1-4, and replaced them with these.
|
103
|
+
module FV5
|
104
|
+
CREATE_NEW = 0x00000000
|
105
|
+
CREATE_TRUNCATE = 0x00000001
|
106
|
+
OPEN_EXISTING = 0x00000002
|
107
|
+
OPEN_OR_CREATE = 0x00000003
|
108
|
+
TRUNCATE_EXISTING = 0x00000004
|
109
|
+
|
110
|
+
APPEND_DATA = 0x00000008
|
111
|
+
APPEND_DATA_ATOMIC = 0x00000010
|
112
|
+
TEXT_MODE = 0x00000020
|
113
|
+
READ_LOCK = 0x00000040
|
114
|
+
WRITE_LOCK = 0x00000080
|
115
|
+
DELETE_LOCK = 0x00000100
|
116
|
+
end
|
117
|
+
|
118
|
+
# Version 6 of the open operation added these flags, in addition to the
|
119
|
+
# flags understood by version 5.
|
120
|
+
module FV6
|
121
|
+
ADVISORY_LOCK = 0x00000200
|
122
|
+
NOFOLLOW = 0x00000400
|
123
|
+
DELETE_ON_CLOSE = 0x00000800
|
124
|
+
ACCESS_AUDIT_ALARM_INFO = 0x00001000
|
125
|
+
ACCESS_BACKUP = 0x00002000
|
126
|
+
BACKUP_STREAM = 0x00004000
|
127
|
+
OVERRIDE_OWNER = 0x00008000
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# The Net::SFTP::Session#block operation, implemented in version 6 of
|
132
|
+
# the protocol, understands these constants for the +mask+ parameter.
|
133
|
+
module LockTypes
|
134
|
+
READ = OpenFlags::FV5::READ_LOCK
|
135
|
+
WRITE = OpenFlags::FV5::WRITE_LOCK
|
136
|
+
DELETE = OpenFlags::FV5::DELETE_LOCK
|
137
|
+
ADVISORY = OpenFlags::FV6::ADVISORY_LOCK
|
138
|
+
end
|
139
|
+
|
140
|
+
module ACE
|
141
|
+
# Access control entry types, used from version 4 of the protocol,
|
142
|
+
# onward. See Net::SFTP::Protocol::V04::Attributes::ACL.
|
143
|
+
module Type
|
144
|
+
ACCESS_ALLOWED = 0x00000000
|
145
|
+
ACCESS_DENIED = 0x00000001
|
146
|
+
SYSTEM_AUDIT = 0x00000002
|
147
|
+
SYSTEM_ALARM = 0x00000003
|
148
|
+
end
|
149
|
+
|
150
|
+
# Access control entry flags, used from version 4 of the protocol,
|
151
|
+
# onward. See Net::SFTP::Protocol::V04::Attributes::ACL.
|
152
|
+
module Flag
|
153
|
+
FILE_INHERIT = 0x00000001
|
154
|
+
DIRECTORY_INHERIT = 0x00000002
|
155
|
+
NO_PROPAGATE_INHERIT = 0x00000004
|
156
|
+
INHERIT_ONLY = 0x00000008
|
157
|
+
SUCCESSFUL_ACCESS = 0x00000010
|
158
|
+
FAILED_ACCESS = 0x00000020
|
159
|
+
IDENTIFIER_GROUP = 0x00000040
|
160
|
+
end
|
161
|
+
|
162
|
+
# Access control entry masks, used from version 4 of the protocol,
|
163
|
+
# onward. See Net::SFTP::Protocol::V04::Attributes::ACL.
|
164
|
+
module Mask
|
165
|
+
READ_DATA = 0x00000001
|
166
|
+
LIST_DIRECTORY = 0x00000001
|
167
|
+
WRITE_DATA = 0x00000002
|
168
|
+
ADD_FILE = 0x00000002
|
169
|
+
APPEND_DATA = 0x00000004
|
170
|
+
ADD_SUBDIRECTORY = 0x00000004
|
171
|
+
READ_NAMED_ATTRS = 0x00000008
|
172
|
+
WRITE_NAMED_ATTRS = 0x00000010
|
173
|
+
EXECUTE = 0x00000020
|
174
|
+
DELETE_CHILD = 0x00000040
|
175
|
+
READ_ATTRIBUTES = 0x00000080
|
176
|
+
WRITE_ATTRIBUTES = 0x00000100
|
177
|
+
DELETE = 0x00010000
|
178
|
+
READ_ACL = 0x00020000
|
179
|
+
WRITE_ACL = 0x00040000
|
180
|
+
WRITE_OWNER = 0x00080000
|
181
|
+
SYNCHRONIZE = 0x00100000
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Net; module SFTP
|
2
|
+
|
3
|
+
# The base exception class for the SFTP system.
|
4
|
+
class Exception < RuntimeError; end
|
5
|
+
|
6
|
+
# A exception class for reporting a non-success result of an operation.
|
7
|
+
class StatusException < Net::SFTP::Exception
|
8
|
+
|
9
|
+
# The response object that caused the exception.
|
10
|
+
attr_reader :response
|
11
|
+
|
12
|
+
# The error code (numeric)
|
13
|
+
attr_reader :code
|
14
|
+
|
15
|
+
# The description of the error
|
16
|
+
attr_reader :description
|
17
|
+
|
18
|
+
# Any incident-specific text given when the exception was raised
|
19
|
+
attr_reader :text
|
20
|
+
|
21
|
+
# Create a new status exception that reports the given code and
|
22
|
+
# description.
|
23
|
+
def initialize(response, text=nil)
|
24
|
+
@response, @text = response, text
|
25
|
+
@code = response.code
|
26
|
+
@description = response.message
|
27
|
+
@description = Response::MAP[@code] if @description.nil? || @description.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
# Override the default message format, to include the code and
|
31
|
+
# description.
|
32
|
+
def message
|
33
|
+
m = super.dup
|
34
|
+
m << " #{text}" if text
|
35
|
+
m << " (#{code}, #{description.inspect})"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end; end
|