redcar 0.3.8.3 → 0.3.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/Rakefile +1 -1
- data/lib/redcar.rb +1 -1
- data/lib/redcar/installer.rb +14 -4
- metadata +1 -168
- data/lib/openssl/Manifest.txt +0 -99
- data/lib/openssl/build.properties +0 -7
- data/lib/plugin_manager/plugin_manager.gemspec +0 -33
- data/plugins/project/vendor/net-sftp/Manifest +0 -55
- data/plugins/project/vendor/net-sftp/Rakefile +0 -30
- data/plugins/project/vendor/net-sftp/lib/net/sftp.rb +0 -70
- data/plugins/project/vendor/net-sftp/lib/net/sftp/constants.rb +0 -187
- data/plugins/project/vendor/net-sftp/lib/net/sftp/errors.rb +0 -39
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/dir.rb +0 -93
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/download.rb +0 -364
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file.rb +0 -176
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file_factory.rb +0 -60
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/upload.rb +0 -387
- data/plugins/project/vendor/net-sftp/lib/net/sftp/packet.rb +0 -21
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol.rb +0 -32
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/attributes.rb +0 -315
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/base.rb +0 -268
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/name.rb +0 -43
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/02/base.rb +0 -31
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/03/base.rb +0 -35
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/attributes.rb +0 -152
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/base.rb +0 -94
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/name.rb +0 -67
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/05/base.rb +0 -66
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/attributes.rb +0 -107
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/base.rb +0 -63
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/base.rb +0 -50
- data/plugins/project/vendor/net-sftp/lib/net/sftp/request.rb +0 -91
- data/plugins/project/vendor/net-sftp/lib/net/sftp/response.rb +0 -76
- data/plugins/project/vendor/net-sftp/lib/net/sftp/session.rb +0 -951
- data/plugins/project/vendor/net-sftp/lib/net/sftp/version.rb +0 -18
- data/plugins/project/vendor/net-sftp/setup.rb +0 -1331
- data/plugins/project/vendor/net-sftp/test/common.rb +0 -171
- data/plugins/project/vendor/net-sftp/test/protocol/01/test_attributes.rb +0 -97
- data/plugins/project/vendor/net-sftp/test/protocol/01/test_base.rb +0 -210
- data/plugins/project/vendor/net-sftp/test/protocol/01/test_name.rb +0 -27
- data/plugins/project/vendor/net-sftp/test/protocol/02/test_base.rb +0 -26
- data/plugins/project/vendor/net-sftp/test/protocol/03/test_base.rb +0 -27
- data/plugins/project/vendor/net-sftp/test/protocol/04/test_attributes.rb +0 -148
- data/plugins/project/vendor/net-sftp/test/protocol/04/test_base.rb +0 -74
- data/plugins/project/vendor/net-sftp/test/protocol/04/test_name.rb +0 -53
- data/plugins/project/vendor/net-sftp/test/protocol/05/test_base.rb +0 -62
- data/plugins/project/vendor/net-sftp/test/protocol/06/test_attributes.rb +0 -124
- data/plugins/project/vendor/net-sftp/test/protocol/06/test_base.rb +0 -51
- data/plugins/project/vendor/net-sftp/test/protocol/test_base.rb +0 -42
- data/plugins/project/vendor/net-sftp/test/test_all.rb +0 -7
- data/plugins/project/vendor/net-sftp/test/test_dir.rb +0 -47
- data/plugins/project/vendor/net-sftp/test/test_download.rb +0 -252
- data/plugins/project/vendor/net-sftp/test/test_file.rb +0 -159
- data/plugins/project/vendor/net-sftp/test/test_file_factory.rb +0 -48
- data/plugins/project/vendor/net-sftp/test/test_packet.rb +0 -9
- data/plugins/project/vendor/net-sftp/test/test_protocol.rb +0 -17
- data/plugins/project/vendor/net-sftp/test/test_request.rb +0 -71
- data/plugins/project/vendor/net-sftp/test/test_response.rb +0 -53
- data/plugins/project/vendor/net-sftp/test/test_session.rb +0 -741
- data/plugins/project/vendor/net-sftp/test/test_upload.rb +0 -219
- data/plugins/project/vendor/net-ssh/Manifest +0 -110
- data/plugins/project/vendor/net-ssh/Rakefile +0 -85
- data/plugins/project/vendor/net-ssh/Rudyfile +0 -96
- data/plugins/project/vendor/net-ssh/lib/net/ssh.rb +0 -215
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/agent.rb +0 -179
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/constants.rb +0 -18
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/key_manager.rb +0 -193
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +0 -60
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +0 -71
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +0 -66
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/password.rb +0 -39
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +0 -92
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/pageant.rb +0 -183
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/session.rb +0 -134
- data/plugins/project/vendor/net-ssh/lib/net/ssh/buffer.rb +0 -340
- data/plugins/project/vendor/net-ssh/lib/net/ssh/buffered_io.rb +0 -198
- data/plugins/project/vendor/net-ssh/lib/net/ssh/config.rb +0 -202
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/channel.rb +0 -630
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/constants.rb +0 -33
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/session.rb +0 -597
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/term.rb +0 -178
- data/plugins/project/vendor/net-ssh/lib/net/ssh/errors.rb +0 -85
- data/plugins/project/vendor/net-ssh/lib/net/ssh/key_factory.rb +0 -102
- data/plugins/project/vendor/net-ssh/lib/net/ssh/known_hosts.rb +0 -129
- data/plugins/project/vendor/net-ssh/lib/net/ssh/loggable.rb +0 -61
- data/plugins/project/vendor/net-ssh/lib/net/ssh/packet.rb +0 -102
- data/plugins/project/vendor/net-ssh/lib/net/ssh/prompt.rb +0 -93
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/command.rb +0 -75
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/errors.rb +0 -14
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/http.rb +0 -94
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks4.rb +0 -70
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks5.rb +0 -142
- data/plugins/project/vendor/net-ssh/lib/net/ssh/ruby_compat.rb +0 -43
- data/plugins/project/vendor/net-ssh/lib/net/ssh/service/forward.rb +0 -288
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test.rb +0 -89
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/channel.rb +0 -129
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/extensions.rb +0 -152
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/kex.rb +0 -44
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/local_packet.rb +0 -51
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/packet.rb +0 -81
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/remote_packet.rb +0 -38
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/script.rb +0 -157
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/socket.rb +0 -64
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/algorithms.rb +0 -384
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/cipher_factory.rb +0 -97
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/constants.rb +0 -30
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac.rb +0 -31
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +0 -79
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5.rb +0 -12
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +0 -11
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/none.rb +0 -15
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +0 -13
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +0 -11
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/identity_cipher.rb +0 -55
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex.rb +0 -13
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +0 -208
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +0 -77
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/openssl.rb +0 -128
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/packet_stream.rb +0 -235
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/server_version.rb +0 -71
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/session.rb +0 -276
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/state.rb +0 -206
- data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/lenient.rb +0 -30
- data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/null.rb +0 -12
- data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/strict.rb +0 -53
- data/plugins/project/vendor/net-ssh/lib/net/ssh/version.rb +0 -62
- data/plugins/project/vendor/net-ssh/net-ssh.gemspec +0 -138
- data/plugins/project/vendor/net-ssh/setup.rb +0 -1585
- data/plugins/project/vendor/net-ssh/support/arcfour_check.rb +0 -20
- data/plugins/project/vendor/net-ssh/support/ssh_tunnel_bug.rb +0 -65
- data/plugins/project/vendor/net-ssh/test/README.txt +0 -42
- data/plugins/project/vendor/net-ssh/test/authentication/methods/common.rb +0 -28
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_abstract.rb +0 -51
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_hostbased.rb +0 -114
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +0 -98
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_password.rb +0 -50
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_publickey.rb +0 -127
- data/plugins/project/vendor/net-ssh/test/authentication/test_agent.rb +0 -205
- data/plugins/project/vendor/net-ssh/test/authentication/test_key_manager.rb +0 -105
- data/plugins/project/vendor/net-ssh/test/authentication/test_session.rb +0 -93
- data/plugins/project/vendor/net-ssh/test/common.rb +0 -107
- data/plugins/project/vendor/net-ssh/test/configs/eqsign +0 -3
- data/plugins/project/vendor/net-ssh/test/configs/exact_match +0 -8
- data/plugins/project/vendor/net-ssh/test/configs/host_plus +0 -10
- data/plugins/project/vendor/net-ssh/test/configs/multihost +0 -4
- data/plugins/project/vendor/net-ssh/test/configs/nohost +0 -19
- data/plugins/project/vendor/net-ssh/test/configs/numeric_host +0 -4
- data/plugins/project/vendor/net-ssh/test/configs/wild_cards +0 -14
- data/plugins/project/vendor/net-ssh/test/connection/test_channel.rb +0 -467
- data/plugins/project/vendor/net-ssh/test/connection/test_session.rb +0 -488
- data/plugins/project/vendor/net-ssh/test/manual/test_forward.rb +0 -185
- data/plugins/project/vendor/net-ssh/test/test_all.rb +0 -9
- data/plugins/project/vendor/net-ssh/test/test_buffer.rb +0 -336
- data/plugins/project/vendor/net-ssh/test/test_buffered_io.rb +0 -63
- data/plugins/project/vendor/net-ssh/test/test_config.rb +0 -117
- data/plugins/project/vendor/net-ssh/test/test_key_factory.rb +0 -67
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5.rb +0 -39
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5_96.rb +0 -25
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_none.rb +0 -34
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1.rb +0 -34
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1_96.rb +0 -25
- data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -146
- data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -92
- data/plugins/project/vendor/net-ssh/test/transport/test_algorithms.rb +0 -302
- data/plugins/project/vendor/net-ssh/test/transport/test_cipher_factory.rb +0 -213
- data/plugins/project/vendor/net-ssh/test/transport/test_hmac.rb +0 -34
- data/plugins/project/vendor/net-ssh/test/transport/test_identity_cipher.rb +0 -40
- data/plugins/project/vendor/net-ssh/test/transport/test_packet_stream.rb +0 -441
- data/plugins/project/vendor/net-ssh/test/transport/test_server_version.rb +0 -78
- data/plugins/project/vendor/net-ssh/test/transport/test_session.rb +0 -315
- data/plugins/project/vendor/net-ssh/test/transport/test_state.rb +0 -173
@@ -1,30 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift "../net-ssh/lib"
|
2
|
-
require './lib/net/sftp/version'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'echoe'
|
6
|
-
rescue LoadError
|
7
|
-
abort "You'll need to have `echoe' installed to use Net::SFTP's Rakefile"
|
8
|
-
end
|
9
|
-
|
10
|
-
version = Net::SFTP::Version::STRING.dup
|
11
|
-
if ENV['SNAPSHOT'].to_i == 1
|
12
|
-
version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
|
13
|
-
end
|
14
|
-
|
15
|
-
Echoe.new('net-sftp', version) do |p|
|
16
|
-
p.project = "net-ssh"
|
17
|
-
p.changelog = "CHANGELOG.rdoc"
|
18
|
-
|
19
|
-
p.author = "Jamis Buck"
|
20
|
-
p.email = "jamis@jamisbuck.org"
|
21
|
-
p.summary = "A pure Ruby implementation of the SFTP client protocol"
|
22
|
-
p.url = "http://net-ssh.rubyforge.org/sftp"
|
23
|
-
|
24
|
-
p.dependencies = ["net-ssh >=2.0.9"]
|
25
|
-
|
26
|
-
p.need_zip = true
|
27
|
-
p.include_rakefile = true
|
28
|
-
|
29
|
-
p.rdoc_pattern = /^(lib|README.rdoc|CHANGELOG.rdoc)/
|
30
|
-
end
|
@@ -1,70 +0,0 @@
|
|
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
|
-
def self.start(host, user, options={}, &block)
|
31
|
-
session = Net::SSH.start(host, user, options)
|
32
|
-
sftp = Net::SFTP::Session.new(session, &block).connect!
|
33
|
-
|
34
|
-
if block_given?
|
35
|
-
sftp.loop
|
36
|
-
session.close
|
37
|
-
return nil
|
38
|
-
end
|
39
|
-
|
40
|
-
sftp
|
41
|
-
rescue Object => anything
|
42
|
-
begin
|
43
|
-
session.shutdown!
|
44
|
-
rescue ::Exception
|
45
|
-
# swallow exceptions that occur while trying to shutdown
|
46
|
-
end
|
47
|
-
|
48
|
-
raise anything
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
class Net::SSH::Connection::Session
|
55
|
-
# A convenience method for starting up a new SFTP connection on the current
|
56
|
-
# SSH session. Blocks until the SFTP session is fully open, and then
|
57
|
-
# returns the SFTP session.
|
58
|
-
#
|
59
|
-
# Net::SSH.start("localhost", "user", "password") do |ssh|
|
60
|
-
# ssh.sftp.upload!("/local/file.tgz", "/remote/file.tgz")
|
61
|
-
# ssh.exec! "cd /some/path && tar xf /remote/file.tgz && rm /remote/file.tgz"
|
62
|
-
# end
|
63
|
-
def sftp(wait=true)
|
64
|
-
@sftp ||= begin
|
65
|
-
sftp = Net::SFTP::Session.new(self)
|
66
|
-
sftp.connect! if wait
|
67
|
-
sftp
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,187 +0,0 @@
|
|
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
|
@@ -1,39 +0,0 @@
|
|
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
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'net/ssh/loggable'
|
2
|
-
|
3
|
-
module Net; module SFTP; module Operations
|
4
|
-
|
5
|
-
# A convenience class for working with remote directories. It provides methods
|
6
|
-
# for searching and enumerating directory entries, similarly to the standard
|
7
|
-
# ::Dir class.
|
8
|
-
#
|
9
|
-
# sftp.dir.foreach("/remote/path") do |entry|
|
10
|
-
# puts entry.name
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# p sftp.dir.entries("/remote/path").map { |e| e.name }
|
14
|
-
#
|
15
|
-
# sftp.dir.glob("/remote/path", "**/*.rb") do |entry|
|
16
|
-
# puts entry.name
|
17
|
-
# end
|
18
|
-
class Dir
|
19
|
-
# The SFTP session object that drives this directory factory.
|
20
|
-
attr_reader :sftp
|
21
|
-
|
22
|
-
# Create a new instance on top of the given SFTP session instance.
|
23
|
-
def initialize(sftp)
|
24
|
-
@sftp = sftp
|
25
|
-
end
|
26
|
-
|
27
|
-
# Calls the block once for each entry in the named directory on the
|
28
|
-
# remote server. Yields a Name object to the block, rather than merely
|
29
|
-
# the name of the entry.
|
30
|
-
def foreach(path)
|
31
|
-
handle = sftp.opendir!(path)
|
32
|
-
while entries = sftp.readdir!(handle)
|
33
|
-
entries.each { |entry| yield entry }
|
34
|
-
end
|
35
|
-
return nil
|
36
|
-
ensure
|
37
|
-
sftp.close!(handle) if handle
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns an array of Name objects representing the items in the given
|
41
|
-
# remote directory, +path+.
|
42
|
-
def entries(path)
|
43
|
-
results = []
|
44
|
-
foreach(path) { |entry| results << entry }
|
45
|
-
return results
|
46
|
-
end
|
47
|
-
|
48
|
-
# Works as ::Dir.glob, matching (possibly recursively) all directory
|
49
|
-
# entries under +path+ against +pattern+. If a block is given, matches
|
50
|
-
# will be yielded to the block as they are found; otherwise, they will
|
51
|
-
# be returned in an array when the method finishes.
|
52
|
-
#
|
53
|
-
# Because working over an SFTP connection is always going to be slower than
|
54
|
-
# working purely locally, don't expect this method to perform with the
|
55
|
-
# same level of alacrity that ::Dir.glob does; it will work best for
|
56
|
-
# shallow directory hierarchies with relatively few directories, though
|
57
|
-
# it should be able to handle modest numbers of files in each directory.
|
58
|
-
def glob(path, pattern, flags=0)
|
59
|
-
flags |= ::File::FNM_PATHNAME
|
60
|
-
path = path.chop if path[-1,1] == "/"
|
61
|
-
|
62
|
-
results = [] unless block_given?
|
63
|
-
queue = entries(path).reject { |e| e.name == "." || e.name == ".." }
|
64
|
-
while queue.any?
|
65
|
-
entry = queue.shift
|
66
|
-
|
67
|
-
if entry.directory? && !%w(. ..).include?(::File.basename(entry.name))
|
68
|
-
queue += entries("#{path}/#{entry.name}").map do |e|
|
69
|
-
e.name.replace("#{entry.name}/#{e.name}")
|
70
|
-
e
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
if ::File.fnmatch(pattern, entry.name, flags)
|
75
|
-
if block_given?
|
76
|
-
yield entry
|
77
|
-
else
|
78
|
-
results << entry
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
return results unless block_given?
|
84
|
-
end
|
85
|
-
|
86
|
-
# Identical to calling #glob with a +flags+ parameter of 0 and no block.
|
87
|
-
# Simply returns the matched entries as an array.
|
88
|
-
def [](path, pattern)
|
89
|
-
glob(path, pattern, 0)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end; end; end
|
@@ -1,364 +0,0 @@
|
|
1
|
-
require 'net/ssh/loggable'
|
2
|
-
|
3
|
-
module Net; module SFTP; module Operations
|
4
|
-
|
5
|
-
# A general purpose downloader module for Net::SFTP. It can download files
|
6
|
-
# into IO objects, or directly to files on the local file system. It can
|
7
|
-
# even download entire directory trees via SFTP, and provides a flexible
|
8
|
-
# progress reporting mechanism.
|
9
|
-
#
|
10
|
-
# To download a single file from the remote server, simply specify both the
|
11
|
-
# remote and local paths:
|
12
|
-
#
|
13
|
-
# downloader = sftp.download("/path/to/remote.txt", "/path/to/local.txt")
|
14
|
-
#
|
15
|
-
# By default, this operates asynchronously, so if you want to block until
|
16
|
-
# the download finishes, you can use the 'bang' variant:
|
17
|
-
#
|
18
|
-
# sftp.download!("/path/to/remote.txt", "/path/to/local.txt")
|
19
|
-
#
|
20
|
-
# Or, if you have multiple downloads that you want to run in parallel, you can
|
21
|
-
# employ the #wait method of the returned object:
|
22
|
-
#
|
23
|
-
# dls = %w(file1 file2 file3).map { |f| sftp.download("remote/#{f}", f) }
|
24
|
-
# dls.each { |d| d.wait }
|
25
|
-
#
|
26
|
-
# To download an entire directory tree, recursively, simply specify :recursive => true:
|
27
|
-
#
|
28
|
-
# sftp.download!("/path/to/remotedir", "/path/to/local", :recursive => true)
|
29
|
-
#
|
30
|
-
# This will download "/path/to/remotedir", it's contents, it's subdirectories,
|
31
|
-
# and their contents, recursively, to "/path/to/local" on the local host.
|
32
|
-
# (If you specify :recursive => true and the source is not a directory,
|
33
|
-
# you'll get an error!)
|
34
|
-
#
|
35
|
-
# If you want to pull the contents of a file on the remote server, and store
|
36
|
-
# the data in memory rather than immediately to disk, you can pass an IO
|
37
|
-
# object as the destination:
|
38
|
-
#
|
39
|
-
# require 'stringio'
|
40
|
-
# io = StringIO.new
|
41
|
-
# sftp.download!("/path/to/remote", io)
|
42
|
-
#
|
43
|
-
# This will only work for single-file downloads. Trying to do so with
|
44
|
-
# :recursive => true will cause an error.
|
45
|
-
#
|
46
|
-
# The following options are supported:
|
47
|
-
#
|
48
|
-
# * <tt>:progress</tt> - either a block or an object to act as a progress
|
49
|
-
# callback. See the discussion of "progress monitoring" below.
|
50
|
-
# * <tt>:requests</tt> - the number of pending SFTP requests to allow at
|
51
|
-
# any given time. When downloading an entire directory tree recursively,
|
52
|
-
# this will default to 16. Setting this higher might improve throughput.
|
53
|
-
# Reducing it will reduce throughput.
|
54
|
-
# * <tt>:read_size</tt> - the maximum number of bytes to read at a time
|
55
|
-
# from the source. Increasing this value might improve throughput. It
|
56
|
-
# defaults to 32,000 bytes.
|
57
|
-
#
|
58
|
-
# == Progress Monitoring
|
59
|
-
#
|
60
|
-
# Sometimes it is desirable to track the progress of a download. There are
|
61
|
-
# two ways to do this: either using a callback block, or a special custom
|
62
|
-
# object.
|
63
|
-
#
|
64
|
-
# Using a block it's pretty straightforward:
|
65
|
-
#
|
66
|
-
# sftp.download!("remote", "local") do |event, downloader, *args|
|
67
|
-
# case event
|
68
|
-
# when :open then
|
69
|
-
# # args[0] : file metadata
|
70
|
-
# puts "starting download: #{args[0].remote} -> #{args[0].local} (#{args[0].size} bytes}"
|
71
|
-
# when :get then
|
72
|
-
# # args[0] : file metadata
|
73
|
-
# # args[1] : byte offset in remote file
|
74
|
-
# # args[2] : data that was received
|
75
|
-
# puts "writing #{args[2].length} bytes to #{args[0].local} starting at #{args[1]}"
|
76
|
-
# when :close then
|
77
|
-
# # args[0] : file metadata
|
78
|
-
# puts "finished with #{args[0].remote}"
|
79
|
-
# when :mkdir then
|
80
|
-
# # args[0] : local path name
|
81
|
-
# puts "creating directory #{args[0]}"
|
82
|
-
# when :finish then
|
83
|
-
# puts "all done!"
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# However, for more complex implementations (e.g., GUI interfaces and such)
|
87
|
-
# a block can become cumbersome. In those cases, you can create custom
|
88
|
-
# handler objects that respond to certain methods, and then pass your handler
|
89
|
-
# to the downloader:
|
90
|
-
#
|
91
|
-
# class CustomHandler
|
92
|
-
# def on_open(downloader, file)
|
93
|
-
# puts "starting download: #{file.remote} -> #{file.local} (#{file.size} bytes)"
|
94
|
-
# end
|
95
|
-
#
|
96
|
-
# def on_get(downloader, file, offset, data)
|
97
|
-
# puts "writing #{data.length} bytes to #{file.local} starting at #{offset}"
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# def on_close(downloader, file)
|
101
|
-
# puts "finished with #{file.remote}"
|
102
|
-
# end
|
103
|
-
#
|
104
|
-
# def on_mkdir(downloader, path)
|
105
|
-
# puts "creating directory #{path}"
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
# def on_finish(downloader)
|
109
|
-
# puts "all done!"
|
110
|
-
# end
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# sftp.download!("remote", "local", :progress => CustomHandler.new)
|
114
|
-
#
|
115
|
-
# If you omit any of those methods, the progress updates for those missing
|
116
|
-
# events will be ignored. You can create a catchall method named "call" for
|
117
|
-
# those, instead.
|
118
|
-
class Download
|
119
|
-
include Net::SSH::Loggable
|
120
|
-
|
121
|
-
# The destination of the download (the name of a file or directory on
|
122
|
-
# the local server, or an IO object)
|
123
|
-
attr_reader :local
|
124
|
-
|
125
|
-
# The source of the download (the name of a file or directory on the
|
126
|
-
# remote server)
|
127
|
-
attr_reader :remote
|
128
|
-
|
129
|
-
# The hash of options that was given to this Download instance.
|
130
|
-
attr_reader :options
|
131
|
-
|
132
|
-
# The SFTP session instance that drives this download.
|
133
|
-
attr_reader :sftp
|
134
|
-
|
135
|
-
# The properties hash for this object
|
136
|
-
attr_reader :properties
|
137
|
-
|
138
|
-
# Instantiates a new downloader process on top of the given SFTP session.
|
139
|
-
# +local+ is either an IO object that should receive the data, or a string
|
140
|
-
# identifying the target file or directory on the local host. +remote+ is
|
141
|
-
# a string identifying the location on the remote host that the download
|
142
|
-
# should source.
|
143
|
-
#
|
144
|
-
# This will return immediately, and requires that the SSH event loop be
|
145
|
-
# run in order to effect the download. (See #wait.)
|
146
|
-
def initialize(sftp, local, remote, options={}, &progress)
|
147
|
-
@sftp = sftp
|
148
|
-
@local = local
|
149
|
-
@remote = remote
|
150
|
-
@progress = progress || options[:progress]
|
151
|
-
@options = options
|
152
|
-
@active = 0
|
153
|
-
@properties = options[:properties] || {}
|
154
|
-
|
155
|
-
self.logger = sftp.logger
|
156
|
-
|
157
|
-
if recursive? && local.respond_to?(:write)
|
158
|
-
raise ArgumentError, "cannot download a directory tree in-memory"
|
159
|
-
end
|
160
|
-
|
161
|
-
@stack = [Entry.new(remote, local, recursive?)]
|
162
|
-
process_next_entry
|
163
|
-
end
|
164
|
-
|
165
|
-
# Returns the value of the :recursive key in the options hash that was
|
166
|
-
# given when the object was instantiated.
|
167
|
-
def recursive?
|
168
|
-
options[:recursive]
|
169
|
-
end
|
170
|
-
|
171
|
-
# Returns true if there are any active requests or pending files or
|
172
|
-
# directories.
|
173
|
-
def active?
|
174
|
-
@active > 0 || stack.any?
|
175
|
-
end
|
176
|
-
|
177
|
-
# Forces the transfer to stop.
|
178
|
-
def abort!
|
179
|
-
@active = 0
|
180
|
-
@stack.clear
|
181
|
-
end
|
182
|
-
|
183
|
-
# Runs the SSH event loop for as long as the downloader is active (see
|
184
|
-
# #active?). This can be used to block until the download completes.
|
185
|
-
def wait
|
186
|
-
sftp.loop { active? }
|
187
|
-
self
|
188
|
-
end
|
189
|
-
|
190
|
-
# Returns the property with the given name. This allows Download instances
|
191
|
-
# to store their own state when used as part of a state machine.
|
192
|
-
def [](name)
|
193
|
-
@properties[name.to_sym]
|
194
|
-
end
|
195
|
-
|
196
|
-
# Sets the given property to the given name. This allows Download instances
|
197
|
-
# to store their own state when used as part of a state machine.
|
198
|
-
def []=(name, value)
|
199
|
-
@properties[name.to_sym] = value
|
200
|
-
end
|
201
|
-
|
202
|
-
private
|
203
|
-
|
204
|
-
# A simple struct for encapsulating information about a single remote
|
205
|
-
# file or directory that needs to be downloaded.
|
206
|
-
Entry = Struct.new(:remote, :local, :directory, :size, :handle, :offset, :sink)
|
207
|
-
|
208
|
-
#--
|
209
|
-
# "ruby -w" hates private attributes, so we have to do these longhand
|
210
|
-
#++
|
211
|
-
|
212
|
-
# The stack of Entry instances, indicating which files and directories
|
213
|
-
# on the remote host remain to be downloaded.
|
214
|
-
def stack; @stack; end
|
215
|
-
|
216
|
-
# The progress handler for this instance. Possibly nil.
|
217
|
-
def progress; @progress; end
|
218
|
-
|
219
|
-
# The default read size.
|
220
|
-
DEFAULT_READ_SIZE = 32_000
|
221
|
-
|
222
|
-
# The number of bytes to read at a time from remote files.
|
223
|
-
def read_size
|
224
|
-
options[:read_size] || DEFAULT_READ_SIZE
|
225
|
-
end
|
226
|
-
|
227
|
-
# The number of simultaneou SFTP requests to use to effect the download.
|
228
|
-
# Defaults to 16 for recursive downloads.
|
229
|
-
def requests
|
230
|
-
options[:requests] || (recursive? ? 16 : 2)
|
231
|
-
end
|
232
|
-
|
233
|
-
# Enqueues as many files and directories from the stack as possible
|
234
|
-
# (see #requests).
|
235
|
-
def process_next_entry
|
236
|
-
while stack.any? && requests > @active
|
237
|
-
entry = stack.shift
|
238
|
-
@active += 1
|
239
|
-
|
240
|
-
if entry.directory
|
241
|
-
update_progress(:mkdir, entry.local)
|
242
|
-
::Dir.mkdir(entry.local) unless ::File.directory?(entry.local)
|
243
|
-
request = sftp.opendir(entry.remote, &method(:on_opendir))
|
244
|
-
request[:entry] = entry
|
245
|
-
else
|
246
|
-
open_file(entry)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
update_progress(:finish) if !active?
|
251
|
-
end
|
252
|
-
|
253
|
-
# Called when a remote directory is "opened" for reading, e.g. to
|
254
|
-
# enumerate its contents. Starts an readdir operation if the opendir
|
255
|
-
# operation was successful.
|
256
|
-
def on_opendir(response)
|
257
|
-
entry = response.request[:entry]
|
258
|
-
raise "opendir #{entry.remote}: #{response}" unless response.ok?
|
259
|
-
entry.handle = response[:handle]
|
260
|
-
request = sftp.readdir(response[:handle], &method(:on_readdir))
|
261
|
-
request[:parent] = entry
|
262
|
-
end
|
263
|
-
|
264
|
-
# Called when the next batch of items is read from a directory on the
|
265
|
-
# remote server. If any items were read, they are added to the queue
|
266
|
-
# and #process_next_entry is called.
|
267
|
-
def on_readdir(response)
|
268
|
-
entry = response.request[:parent]
|
269
|
-
if response.eof?
|
270
|
-
request = sftp.close(entry.handle, &method(:on_closedir))
|
271
|
-
request[:parent] = entry
|
272
|
-
elsif !response.ok?
|
273
|
-
raise "readdir #{entry.remote}: #{response}"
|
274
|
-
else
|
275
|
-
response[:names].each do |item|
|
276
|
-
next if item.name == "." || item.name == ".."
|
277
|
-
stack << Entry.new(::File.join(entry.remote, item.name), ::File.join(entry.local, item.name), item.directory?, item.attributes.size)
|
278
|
-
end
|
279
|
-
|
280
|
-
# take this opportunity to enqueue more requests
|
281
|
-
process_next_entry
|
282
|
-
|
283
|
-
request = sftp.readdir(entry.handle, &method(:on_readdir))
|
284
|
-
request[:parent] = entry
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
# Called when a file is to be opened for reading from the remote server.
|
289
|
-
def open_file(entry)
|
290
|
-
update_progress(:open, entry)
|
291
|
-
request = sftp.open(entry.remote, &method(:on_open))
|
292
|
-
request[:entry] = entry
|
293
|
-
end
|
294
|
-
|
295
|
-
# Called when a directory handle is closed.
|
296
|
-
def on_closedir(response)
|
297
|
-
@active -= 1
|
298
|
-
entry = response.request[:parent]
|
299
|
-
raise "close #{entry.remote}: #{response}" unless response.ok?
|
300
|
-
process_next_entry
|
301
|
-
end
|
302
|
-
|
303
|
-
# Called when a file has been opened. This will call #download_next_chunk
|
304
|
-
# to initiate the data transfer.
|
305
|
-
def on_open(response)
|
306
|
-
entry = response.request[:entry]
|
307
|
-
raise "open #{entry.remote}: #{response}" unless response.ok?
|
308
|
-
|
309
|
-
entry.handle = response[:handle]
|
310
|
-
entry.sink = entry.local.respond_to?(:write) ? entry.local : ::File.open(entry.local, "wb")
|
311
|
-
entry.offset = 0
|
312
|
-
|
313
|
-
download_next_chunk(entry)
|
314
|
-
end
|
315
|
-
|
316
|
-
# Initiates a read of the next #read_size bytes from the file.
|
317
|
-
def download_next_chunk(entry)
|
318
|
-
request = sftp.read(entry.handle, entry.offset, read_size, &method(:on_read))
|
319
|
-
request[:entry] = entry
|
320
|
-
request[:offset] = entry.offset
|
321
|
-
entry.offset += read_size
|
322
|
-
end
|
323
|
-
|
324
|
-
# Called when a read from a file finishes. If the read was successful
|
325
|
-
# and returned data, this will call #download_next_chunk to read the
|
326
|
-
# next bit from the file. Otherwise the file will be closed.
|
327
|
-
def on_read(response)
|
328
|
-
entry = response.request[:entry]
|
329
|
-
|
330
|
-
if response.eof?
|
331
|
-
update_progress(:close, entry)
|
332
|
-
entry.sink.close
|
333
|
-
request = sftp.close(entry.handle, &method(:on_close))
|
334
|
-
request[:entry] = entry
|
335
|
-
elsif !response.ok?
|
336
|
-
raise "read #{entry.remote}: #{response}"
|
337
|
-
else
|
338
|
-
update_progress(:get, entry, response.request[:offset], response[:data])
|
339
|
-
entry.sink.write(response[:data])
|
340
|
-
download_next_chunk(entry)
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
# Called when a file handle is closed.
|
345
|
-
def on_close(response)
|
346
|
-
@active -= 1
|
347
|
-
entry = response.request[:entry]
|
348
|
-
raise "close #{entry.remote}: #{response}" unless response.ok?
|
349
|
-
process_next_entry
|
350
|
-
end
|
351
|
-
|
352
|
-
# If a progress callback or object has been set, this will report
|
353
|
-
# the progress to that callback or object.
|
354
|
-
def update_progress(hook, *args)
|
355
|
-
on = "on_#{hook}"
|
356
|
-
if progress.respond_to?(on)
|
357
|
-
progress.send(on, self, *args)
|
358
|
-
elsif progress.respond_to?(:call)
|
359
|
-
progress.call(hook, self, *args)
|
360
|
-
end
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
end; end; end
|