net-sftp 1.1.1 → 2.0.0

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.
Files changed (138) hide show
  1. data/CHANGELOG.rdoc +23 -0
  2. data/Manifest +55 -0
  3. data/README.rdoc +96 -0
  4. data/Rakefile +30 -0
  5. data/lib/net/sftp.rb +53 -38
  6. data/lib/net/sftp/constants.rb +187 -0
  7. data/lib/net/sftp/errors.rb +34 -20
  8. data/lib/net/sftp/operations/dir.rb +93 -0
  9. data/lib/net/sftp/operations/download.rb +364 -0
  10. data/lib/net/sftp/operations/file.rb +176 -0
  11. data/lib/net/sftp/operations/file_factory.rb +60 -0
  12. data/lib/net/sftp/operations/upload.rb +387 -0
  13. data/lib/net/sftp/packet.rb +21 -0
  14. data/lib/net/sftp/protocol.rb +32 -0
  15. data/lib/net/sftp/protocol/01/attributes.rb +265 -96
  16. data/lib/net/sftp/protocol/01/base.rb +268 -0
  17. data/lib/net/sftp/protocol/01/name.rb +43 -0
  18. data/lib/net/sftp/protocol/02/base.rb +31 -0
  19. data/lib/net/sftp/protocol/03/base.rb +35 -0
  20. data/lib/net/sftp/protocol/04/attributes.rb +120 -195
  21. data/lib/net/sftp/protocol/04/base.rb +94 -0
  22. data/lib/net/sftp/protocol/04/name.rb +67 -0
  23. data/lib/net/sftp/protocol/05/base.rb +66 -0
  24. data/lib/net/sftp/protocol/06/attributes.rb +107 -0
  25. data/lib/net/sftp/protocol/06/base.rb +63 -0
  26. data/lib/net/sftp/protocol/base.rb +50 -0
  27. data/lib/net/sftp/request.rb +91 -0
  28. data/lib/net/sftp/response.rb +76 -0
  29. data/lib/net/sftp/session.rb +914 -238
  30. data/lib/net/sftp/version.rb +14 -21
  31. data/net-sftp.gemspec +60 -0
  32. data/setup.rb +1331 -0
  33. data/test/common.rb +173 -0
  34. data/test/protocol/01/test_attributes.rb +97 -0
  35. data/test/protocol/01/test_base.rb +210 -0
  36. data/test/protocol/01/test_name.rb +27 -0
  37. data/test/protocol/02/test_base.rb +26 -0
  38. data/test/protocol/03/test_base.rb +27 -0
  39. data/test/protocol/04/test_attributes.rb +148 -0
  40. data/test/protocol/04/test_base.rb +74 -0
  41. data/test/protocol/04/test_name.rb +49 -0
  42. data/test/protocol/05/test_base.rb +62 -0
  43. data/test/protocol/06/test_attributes.rb +124 -0
  44. data/test/protocol/06/test_base.rb +51 -0
  45. data/test/protocol/test_base.rb +42 -0
  46. data/test/test_all.rb +3 -0
  47. data/test/test_dir.rb +47 -0
  48. data/test/test_download.rb +252 -0
  49. data/test/test_file.rb +159 -0
  50. data/test/test_file_factory.rb +48 -0
  51. data/test/test_packet.rb +9 -0
  52. data/test/test_protocol.rb +17 -0
  53. data/test/test_request.rb +71 -0
  54. data/test/test_response.rb +53 -0
  55. data/test/test_session.rb +741 -0
  56. data/test/test_upload.rb +219 -0
  57. metadata +59 -111
  58. data/doc/LICENSE-BSD +0 -27
  59. data/doc/LICENSE-GPL +0 -280
  60. data/doc/LICENSE-RUBY +0 -56
  61. data/doc/faq/faq.html +0 -298
  62. data/doc/faq/faq.rb +0 -154
  63. data/doc/faq/faq.yml +0 -183
  64. data/examples/asynchronous.rb +0 -57
  65. data/examples/get-put.rb +0 -45
  66. data/examples/sftp-open-uri.rb +0 -30
  67. data/examples/ssh-service.rb +0 -30
  68. data/examples/synchronous.rb +0 -131
  69. data/lib/net/sftp/operations/abstract.rb +0 -108
  70. data/lib/net/sftp/operations/close.rb +0 -31
  71. data/lib/net/sftp/operations/errors.rb +0 -76
  72. data/lib/net/sftp/operations/fsetstat.rb +0 -36
  73. data/lib/net/sftp/operations/fstat.rb +0 -32
  74. data/lib/net/sftp/operations/lstat.rb +0 -31
  75. data/lib/net/sftp/operations/mkdir.rb +0 -33
  76. data/lib/net/sftp/operations/open.rb +0 -32
  77. data/lib/net/sftp/operations/opendir.rb +0 -32
  78. data/lib/net/sftp/operations/read.rb +0 -88
  79. data/lib/net/sftp/operations/readdir.rb +0 -55
  80. data/lib/net/sftp/operations/realpath.rb +0 -37
  81. data/lib/net/sftp/operations/remove.rb +0 -31
  82. data/lib/net/sftp/operations/rename.rb +0 -32
  83. data/lib/net/sftp/operations/rmdir.rb +0 -31
  84. data/lib/net/sftp/operations/services.rb +0 -42
  85. data/lib/net/sftp/operations/setstat.rb +0 -33
  86. data/lib/net/sftp/operations/stat.rb +0 -31
  87. data/lib/net/sftp/operations/write.rb +0 -63
  88. data/lib/net/sftp/protocol/01/impl.rb +0 -251
  89. data/lib/net/sftp/protocol/01/packet-assistant.rb +0 -82
  90. data/lib/net/sftp/protocol/01/services.rb +0 -47
  91. data/lib/net/sftp/protocol/02/impl.rb +0 -39
  92. data/lib/net/sftp/protocol/02/packet-assistant.rb +0 -32
  93. data/lib/net/sftp/protocol/02/services.rb +0 -44
  94. data/lib/net/sftp/protocol/03/impl.rb +0 -42
  95. data/lib/net/sftp/protocol/03/packet-assistant.rb +0 -35
  96. data/lib/net/sftp/protocol/03/services.rb +0 -44
  97. data/lib/net/sftp/protocol/04/impl.rb +0 -86
  98. data/lib/net/sftp/protocol/04/packet-assistant.rb +0 -45
  99. data/lib/net/sftp/protocol/04/services.rb +0 -44
  100. data/lib/net/sftp/protocol/05/impl.rb +0 -90
  101. data/lib/net/sftp/protocol/05/packet-assistant.rb +0 -34
  102. data/lib/net/sftp/protocol/05/services.rb +0 -44
  103. data/lib/net/sftp/protocol/constants.rb +0 -60
  104. data/lib/net/sftp/protocol/driver.rb +0 -235
  105. data/lib/net/sftp/protocol/packet-assistant.rb +0 -84
  106. data/lib/net/sftp/protocol/services.rb +0 -55
  107. data/lib/uri/open-sftp.rb +0 -54
  108. data/lib/uri/sftp.rb +0 -42
  109. data/test/ALL-TESTS.rb +0 -23
  110. data/test/operations/tc_abstract.rb +0 -124
  111. data/test/operations/tc_close.rb +0 -40
  112. data/test/operations/tc_fsetstat.rb +0 -48
  113. data/test/operations/tc_fstat.rb +0 -40
  114. data/test/operations/tc_lstat.rb +0 -40
  115. data/test/operations/tc_mkdir.rb +0 -48
  116. data/test/operations/tc_open.rb +0 -42
  117. data/test/operations/tc_opendir.rb +0 -40
  118. data/test/operations/tc_read.rb +0 -103
  119. data/test/operations/tc_readdir.rb +0 -88
  120. data/test/operations/tc_realpath.rb +0 -54
  121. data/test/operations/tc_remove.rb +0 -40
  122. data/test/operations/tc_rmdir.rb +0 -40
  123. data/test/operations/tc_setstat.rb +0 -48
  124. data/test/operations/tc_stat.rb +0 -40
  125. data/test/operations/tc_write.rb +0 -91
  126. data/test/protocol/01/tc_attributes.rb +0 -138
  127. data/test/protocol/01/tc_impl.rb +0 -294
  128. data/test/protocol/01/tc_packet_assistant.rb +0 -81
  129. data/test/protocol/02/tc_impl.rb +0 -41
  130. data/test/protocol/02/tc_packet_assistant.rb +0 -31
  131. data/test/protocol/03/tc_impl.rb +0 -48
  132. data/test/protocol/03/tc_packet_assistant.rb +0 -34
  133. data/test/protocol/04/tc_attributes.rb +0 -174
  134. data/test/protocol/04/tc_impl.rb +0 -91
  135. data/test/protocol/04/tc_packet_assistant.rb +0 -38
  136. data/test/protocol/05/tc_impl.rb +0 -61
  137. data/test/protocol/05/tc_packet_assistant.rb +0 -32
  138. data/test/protocol/tc_driver.rb +0 -219
@@ -1,38 +0,0 @@
1
- #--
2
- # =============================================================================
3
- # Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
4
- # All rights reserved.
5
- #
6
- # This source file is distributed as part of the Net::SFTP Secure FTP Client
7
- # library for Ruby. This file (and the library as a whole) may be used only as
8
- # allowed by either the BSD license, or the Ruby license (or, by association
9
- # with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
10
- # distribution for the texts of these licenses.
11
- # -----------------------------------------------------------------------------
12
- # net-sftp website: http://net-ssh.rubyforge.org/sftp
13
- # project website : http://rubyforge.org/projects/net-ssh
14
- # =============================================================================
15
- #++
16
-
17
- $:.unshift "../../../lib"
18
- $:.unshift File.join( File.dirname( __FILE__ ), ".." )
19
-
20
- require '03/tc_packet_assistant'
21
- require 'net/sftp/protocol/04/packet-assistant'
22
-
23
- class TC_04_PacketAssistant < TC_03_PacketAssistant
24
-
25
- def packet_assistant_class
26
- Net::SFTP::Protocol::V_04::PacketAssistant
27
- end
28
-
29
- packet :rename, [ "old name", "new name", 1 ],
30
- "\0\0\0\10old name\0\0\0\10new name\0\0\0\1"
31
-
32
- packet :stat, [ "a path", 1 ], "\0\0\0\6a path\0\0\0\1"
33
-
34
- packet :lstat, [ "a path", 1 ], "\0\0\0\6a path\0\0\0\1"
35
-
36
- packet :fstat, [ "handle", 1 ], "\0\0\0\6handle\0\0\0\1"
37
-
38
- end
@@ -1,61 +0,0 @@
1
- #--
2
- # =============================================================================
3
- # Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
4
- # All rights reserved.
5
- #
6
- # This source file is distributed as part of the Net::SFTP Secure FTP Client
7
- # library for Ruby. This file (and the library as a whole) may be used only as
8
- # allowed by either the BSD license, or the Ruby license (or, by association
9
- # with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
10
- # distribution for the texts of these licenses.
11
- # -----------------------------------------------------------------------------
12
- # net-sftp website: http://net-ssh.rubyforge.org/sftp
13
- # project website : http://rubyforge.org/projects/net-ssh
14
- # =============================================================================
15
- #++
16
-
17
- $:.unshift "../../../lib"
18
- $:.unshift File.join( File.dirname( __FILE__ ), ".." )
19
-
20
- require 'net/sftp/protocol/05/impl'
21
- require '04/tc_impl'
22
-
23
- class TC_05_Impl < TC_04_Impl
24
-
25
- def impl_class
26
- Net::SFTP::Protocol::V_05::Impl
27
- end
28
-
29
- unless defined?( IO_FLAGS_V4 )
30
- IO_FLAGS_V4 = [ IO::RDONLY, IO::WRONLY, IO::RDWR, IO::APPEND ]
31
- OTHER_FLAGS_V4 = [ 0, IO::CREAT, IO::TRUNC, IO::EXCL ]
32
- FLAG_MAP_V4 = { IO::RDONLY => 2, IO::WRONLY => 1, IO::RDWR => 3,
33
- IO::APPEND => 11, IO::CREAT => 3, IO::TRUNC => 4 }
34
- ACCESS_MAP_V4 = { IO::RDONLY => 0x81, IO::WRONLY => 0x102,
35
- IO::RDWR => 0x183, IO::APPEND => 0x106 }
36
-
37
- IO_FLAGS_V4.each do |flag|
38
- OTHER_FLAGS_V4.each do |oflag|
39
- [ nil, 0400 ].each do |mode|
40
- define_method( "test_open_#{flag}_#{oflag}_#{mode||"nil"}" ) do
41
- return if oflag == IO::EXCL
42
- @assistant.mock_handle( :open ) { |*a| [ a[0], a[1..-1] ] }
43
- args = [ 14, "a path", flag | oflag ]
44
- args << mode if mode
45
- assert_equal 14, @impl.open( *args )
46
- assert_equal 1, @assistant.mock_count( :open )
47
- assert_equal( ( mode || 0660 ), @permissions )
48
- sftp_flag = FLAG_MAP_V4[flag] |
49
- ( oflag == 0 ? 0 : FLAG_MAP_V4[oflag] )
50
- access_flag = ACCESS_MAP_V4[flag]
51
- assert_equal Net::SFTP::Protocol::Constants::FXP_OPEN,
52
- @sent_data.first[0]
53
- assert_equal [ "a path", access_flag, sftp_flag ],
54
- @sent_data.first[1][0,3]
55
- end
56
- end
57
- end
58
- end
59
- end
60
-
61
- end
@@ -1,32 +0,0 @@
1
- #--
2
- # =============================================================================
3
- # Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
4
- # All rights reserved.
5
- #
6
- # This source file is distributed as part of the Net::SFTP Secure FTP Client
7
- # library for Ruby. This file (and the library as a whole) may be used only as
8
- # allowed by either the BSD license, or the Ruby license (or, by association
9
- # with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
10
- # distribution for the texts of these licenses.
11
- # -----------------------------------------------------------------------------
12
- # net-sftp website: http://net-ssh.rubyforge.org/sftp
13
- # project website : http://rubyforge.org/projects/net-ssh
14
- # =============================================================================
15
- #++
16
-
17
- $:.unshift "../../../lib"
18
- $:.unshift File.join( File.dirname( __FILE__ ), ".." )
19
-
20
- require '04/tc_packet_assistant'
21
- require 'net/sftp/protocol/05/packet-assistant'
22
-
23
- class TC_05_PacketAssistant < TC_04_PacketAssistant
24
-
25
- def packet_assistant_class
26
- Net::SFTP::Protocol::V_05::PacketAssistant
27
- end
28
-
29
- packet :open, [ "a path", 1, 2, "attrs" ],
30
- "\0\0\0\6a path\0\0\0\1\0\0\0\2attrs"
31
-
32
- end
@@ -1,219 +0,0 @@
1
- #--
2
- # =============================================================================
3
- # Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
4
- # All rights reserved.
5
- #
6
- # This source file is distributed as part of the Net::SFTP Secure FTP Client
7
- # library for Ruby. This file (and the library as a whole) may be used only as
8
- # allowed by either the BSD license, or the Ruby license (or, by association
9
- # with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
10
- # distribution for the texts of these licenses.
11
- # -----------------------------------------------------------------------------
12
- # net-sftp website: http://net-ssh.rubyforge.org/sftp
13
- # project website : http://rubyforge.org/projects/net-ssh
14
- # =============================================================================
15
- #++
16
-
17
- $:.unshift "../../lib"
18
-
19
- require 'test/unit'
20
- require 'net/sftp/protocol/driver'
21
- require 'net/ssh/util/buffer'
22
- require 'flexmock'
23
-
24
- class TC_Protocol_Driver < Test::Unit::TestCase
25
-
26
- class Buffers
27
- def writer
28
- Net::SSH::Util::WriterBuffer.new
29
- end
30
- def reader( text )
31
- Net::SSH::Util::ReaderBuffer.new( text )
32
- end
33
- end
34
-
35
- def reader( text )
36
- Net::SSH::Util::ReaderBuffer.new( text )
37
- end
38
-
39
- def force_state( state )
40
- @driver.instance_eval { @state = state }
41
- end
42
-
43
- def setup
44
- @channel = FlexMock.new
45
- @channel.mock_handle( :close )
46
- @channel.mock_handle( :subsystem )
47
- @channel.mock_handle( :on_success )
48
- @channel.mock_handle( :on_data )
49
- @channel.mock_handle( :send_data )
50
-
51
- @connection = FlexMock.new
52
- @connection.mock_handle( :open_channel ) { @channel }
53
-
54
- @log = FlexMock.new
55
- @log.mock_handle( :debug? )
56
- @log.mock_handle( :debug )
57
- @log.mock_handle( :info? )
58
- @log.mock_handle( :info )
59
-
60
- @dispatchers = FlexMock.new
61
-
62
- @dispatcher = FlexMock.new
63
-
64
- @dispatchers.mock_handle( :[] ) do |v,e|
65
- @version = v
66
- @extensions = e
67
- @dispatcher
68
- end
69
-
70
- @driver = Net::SFTP::Protocol::Driver.new( @connection, Buffers.new, 5,
71
- @dispatchers, @log )
72
- end
73
-
74
- def test_initial_state
75
- assert_equal :unconfirmed, @driver.state
76
- end
77
-
78
- def test_close
79
- @driver.close
80
- assert_equal 1, @channel.mock_count( :close )
81
- assert_equal :closed, @driver.state
82
- end
83
-
84
- def test_next_request_id
85
- assert_equal 0, @driver.next_request_id
86
- assert_equal 1, @driver.next_request_id
87
- assert_equal 2, @driver.next_request_id
88
- end
89
-
90
- def test_do_confirm_bad_state
91
- force_state :bogus
92
- assert_raise( Net::SFTP::Bug ) { @driver.do_confirm @channel }
93
- end
94
-
95
- def test_do_confirm
96
- force_state :unconfirmed
97
- @channel.mock_handle( :subsystem ) { |a| assert_equal "sftp", a }
98
- @driver.do_confirm @channel
99
- assert_equal 1, @channel.mock_count( :subsystem )
100
- assert_equal 1, @channel.mock_count( :on_success )
101
- assert_equal 1, @channel.mock_count( :on_data )
102
- assert_equal :init, @driver.state
103
- end
104
-
105
- def test_do_success_bad_state
106
- force_state :bogus
107
- assert_raise( Net::SFTP::Bug ) { @driver.do_success @channel }
108
- end
109
-
110
- def test_do_success
111
- force_state :init
112
- packet = nil
113
- @channel.mock_handle( :send_data ) { |p| packet = p }
114
- @driver.do_success @channel
115
- assert_equal 1, @channel.mock_count( :send_data )
116
- assert_equal "\0\0\0\5\1\0\0\0\5", packet.to_s
117
- end
118
-
119
- def test_version_bad_state
120
- force_state :bogus
121
- assert_raise( Net::SFTP::Bug ) { @driver.do_version nil }
122
- end
123
-
124
- def test_version_server_higher
125
- force_state :version
126
- @driver.do_version reader( "\0\0\0\7" )
127
- assert_equal 5, @version
128
- assert_equal Hash.new, @extensions
129
- assert_equal :open, @driver.state
130
- end
131
-
132
- def test_version_server_lower
133
- force_state :version
134
- @driver.do_version reader( "\0\0\0\3" )
135
- assert_equal 3, @version
136
- assert_equal Hash.new, @extensions
137
- assert_equal :open, @driver.state
138
- end
139
-
140
- def test_version_extensions
141
- force_state :version
142
- @driver.do_version reader( "\0\0\0\3\0\0\0\1a\0\0\0\1b\0\0\0\1c\0\0\0\1d" )
143
- assert_equal( {"a"=>"b","c"=>"d"}, @extensions )
144
- end
145
-
146
- def test_version_with_on_open
147
- force_state :version
148
- called = false
149
- @driver.on_open { called = true }
150
- @driver.do_version reader( "\0\0\0\3" )
151
- assert called
152
- end
153
-
154
- def test_do_data_version
155
- force_state :version
156
- @driver.do_data( nil, "\0\0\0\5\2\0\0\0\3" )
157
- assert_equal 1, @dispatchers.mock_count( :[] )
158
- end
159
-
160
- def test_do_dispatch
161
- # define the dispatcher
162
- force_state :version
163
- @driver.do_version reader( "\0\0\0\3" )
164
-
165
- channel = type = content = 0
166
- @dispatcher.mock_handle( :dispatch ) { |c,t,n|
167
- channel, type, content = c,t,n }
168
- @driver.do_data( nil, "\0\0\0\5\7\0\0\0\0" )
169
- assert_equal 1, @dispatcher.mock_count(:dispatch)
170
- assert_nil channel
171
- assert_equal 7, type
172
- assert_equal "\0\0\0\0", content.to_s
173
- end
174
-
175
- def test_do_dispatch_multipass
176
- # define the dispatcher
177
- force_state :version
178
- @driver.do_version reader( "\0\0\0\3" )
179
-
180
- channel = type = content = 0
181
- @dispatcher.mock_handle( :dispatch ) { |c,t,n|
182
- channel, type, content = c,t,n }
183
- @driver.do_data( nil, "\0\0\0\5\7\0\0" )
184
-
185
- assert_equal 0, @dispatcher.mock_count(:dispatch)
186
- assert_equal 0, channel
187
- assert_equal 0, type
188
- assert_equal 0, content
189
-
190
- @driver.do_data( nil, "\0\0" )
191
-
192
- assert_equal 1, @dispatcher.mock_count(:dispatch)
193
- assert_nil channel
194
- assert_equal 7, type
195
- assert_equal "\0\0\0\0", content.to_s
196
- end
197
-
198
- def test_method_missing_found
199
- force_state :version
200
- @driver.do_version reader( "\0\0\0\3" )
201
-
202
- def @dispatcher.respond_to?(sym)
203
- super || sym == :foo
204
- end
205
-
206
- @dispatcher.mock_handle( :foo )
207
- assert @driver.respond_to?( :foo )
208
-
209
- @driver.foo
210
-
211
- assert_equal 1, @dispatcher.mock_count( :foo )
212
- end
213
-
214
- def test_method_missing_not_found
215
- assert !@driver.respond_to?( :foo )
216
- assert_raise( NoMethodError ) { @driver.foo }
217
- end
218
-
219
- end