net-ssh 0.6.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/manual-html/chapter-1.html +59 -24
- data/doc/manual-html/chapter-2.html +116 -77
- data/doc/manual-html/chapter-3.html +80 -41
- data/doc/manual-html/chapter-4.html +111 -71
- data/doc/manual-html/chapter-5.html +267 -155
- data/doc/manual-html/chapter-6.html +211 -75
- data/doc/manual-html/chapter-7.html +331 -0
- data/doc/manual-html/index.html +39 -13
- data/doc/manual-html/{manual.css → stylesheets/manual.css} +81 -8
- data/doc/manual-html/stylesheets/ruby.css +17 -0
- data/doc/manual/chapter.erb +20 -0
- data/doc/manual/manual.rb +80 -9
- data/doc/manual/manual.yml +12 -2
- data/doc/manual/page.erb +1 -1
- data/doc/manual/parts/channels_callbacks.txt +11 -11
- data/doc/manual/parts/channels_loop.txt +6 -6
- data/doc/manual/parts/channels_open.txt +9 -9
- data/doc/manual/parts/exec_channels.txt +15 -15
- data/doc/manual/parts/exec_open.txt +17 -18
- data/doc/manual/parts/exec_popen3.txt +18 -18
- data/doc/manual/parts/forward_direct.txt +16 -16
- data/doc/manual/parts/forward_intro.txt +7 -7
- data/doc/manual/parts/forward_local.txt +9 -9
- data/doc/manual/parts/forward_remote.txt +9 -9
- data/doc/manual/parts/intro_getting.txt +11 -11
- data/doc/manual/parts/proxy_http.txt +27 -27
- data/doc/manual/parts/proxy_socks.txt +17 -17
- data/doc/manual/parts/session_key.txt +13 -14
- data/doc/manual/parts/session_options.txt +14 -14
- data/doc/manual/parts/session_session.txt +9 -9
- data/doc/manual/parts/session_start.txt +27 -27
- data/doc/manual/parts/shells_channels.txt +72 -0
- data/doc/manual/parts/shells_clients.txt +51 -0
- data/doc/manual/parts/shells_intro.txt +7 -0
- data/doc/manual/parts/shells_shell.txt +50 -0
- data/doc/manual/parts/shells_sync.txt +42 -0
- data/doc/manual/{manual.css → stylesheets/manual.css} +81 -8
- data/doc/manual/stylesheets/ruby.css +17 -0
- data/examples/channel-demo.rb +1 -1
- data/examples/port-forward.rb +1 -1
- data/examples/process-demo.rb +1 -1
- data/examples/remote-net-port-forward.rb +1 -1
- data/examples/remote-port-forward.rb +1 -1
- data/examples/shell-demo.rb +46 -0
- data/examples/ssh-client.rb +67 -0
- data/examples/sync-shell-demo.rb +69 -0
- data/examples/tail-demo.rb +1 -1
- data/lib/net/ssh.rb +1 -1
- data/lib/net/ssh/connection/channel.rb +61 -7
- data/lib/net/ssh/connection/constants.rb +1 -1
- data/lib/net/ssh/connection/driver.rb +61 -8
- data/lib/net/ssh/connection/services.rb +1 -1
- data/lib/net/ssh/connection/term.rb +1 -1
- data/lib/net/ssh/errors.rb +1 -1
- data/lib/net/ssh/proxy/errors.rb +1 -1
- data/lib/net/ssh/proxy/http.rb +1 -1
- data/lib/net/ssh/proxy/socks4.rb +1 -1
- data/lib/net/ssh/proxy/socks5.rb +1 -1
- data/lib/net/ssh/service/forward/driver.rb +1 -1
- data/lib/net/ssh/service/forward/local-network-handler.rb +1 -1
- data/lib/net/ssh/service/forward/remote-network-handler.rb +1 -1
- data/lib/net/ssh/service/forward/services.rb +1 -1
- data/lib/net/ssh/service/process/driver.rb +1 -1
- data/lib/net/ssh/service/process/open.rb +1 -1
- data/lib/net/ssh/service/process/popen3.rb +20 -2
- data/lib/net/ssh/service/process/services.rb +1 -1
- data/lib/net/ssh/service/services.rb +3 -1
- data/lib/net/ssh/service/shell/driver.rb +86 -0
- data/lib/net/ssh/service/shell/services.rb +54 -0
- data/lib/net/ssh/service/shell/shell.rb +213 -0
- data/lib/net/ssh/service/shell/sync.rb +114 -0
- data/lib/net/ssh/session.rb +9 -1
- data/lib/net/ssh/transport/algorithm-negotiator.rb +1 -1
- data/lib/net/ssh/transport/compress/compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/decompressor.rb +1 -1
- data/lib/net/ssh/transport/compress/none-compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/none-decompressor.rb +1 -1
- data/lib/net/ssh/transport/compress/services.rb +1 -1
- data/lib/net/ssh/transport/compress/zlib-compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/zlib-decompressor.rb +1 -1
- data/lib/net/ssh/transport/constants.rb +1 -1
- data/lib/net/ssh/transport/errors.rb +1 -1
- data/lib/net/ssh/transport/identity-cipher.rb +1 -1
- data/lib/net/ssh/transport/kex/dh-gex.rb +1 -1
- data/lib/net/ssh/transport/kex/dh.rb +1 -1
- data/lib/net/ssh/transport/kex/services.rb +1 -1
- data/lib/net/ssh/transport/ossl/buffer-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/buffer.rb +1 -1
- data/lib/net/ssh/transport/ossl/cipher-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/digest-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/hmac.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/md5.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/none.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/services.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/sha1.rb +1 -1
- data/lib/net/ssh/transport/ossl/key-factory.rb +5 -2
- data/lib/net/ssh/transport/ossl/services.rb +1 -1
- data/lib/net/ssh/transport/packet-stream.rb +1 -1
- data/lib/net/ssh/transport/services.rb +1 -1
- data/lib/net/ssh/transport/session.rb +10 -1
- data/lib/net/ssh/transport/version-negotiator.rb +1 -1
- data/lib/net/ssh/userauth/agent.rb +1 -1
- data/lib/net/ssh/userauth/constants.rb +1 -1
- data/lib/net/ssh/userauth/driver.rb +1 -1
- data/lib/net/ssh/userauth/methods/hostbased.rb +1 -1
- data/lib/net/ssh/userauth/methods/keyboard-interactive.rb +104 -0
- data/lib/net/ssh/userauth/methods/password.rb +1 -1
- data/lib/net/ssh/userauth/methods/publickey.rb +1 -1
- data/lib/net/ssh/userauth/methods/services.rb +28 -6
- data/lib/net/ssh/userauth/services.rb +8 -5
- data/lib/net/ssh/userauth/userkeys.rb +1 -1
- data/lib/net/ssh/util/buffer.rb +1 -1
- data/lib/net/ssh/util/openssl.rb +1 -1
- data/lib/net/ssh/util/prompter.rb +1 -1
- data/lib/net/ssh/version.rb +2 -2
- data/test/ALL-TESTS.rb +1 -1
- data/test/connection/tc_channel.rb +1 -1
- data/test/connection/tc_driver.rb +1 -1
- data/test/connection/tc_integration.rb +1 -1
- data/test/proxy/tc_http.rb +1 -1
- data/test/proxy/tc_socks4.rb +1 -1
- data/test/proxy/tc_socks5.rb +1 -1
- data/test/service/forward/tc_driver.rb +1 -1
- data/test/service/forward/tc_local_network_handler.rb +1 -1
- data/test/service/forward/tc_remote_network_handler.rb +1 -1
- data/test/service/process/tc_driver.rb +1 -1
- data/test/service/process/tc_integration.rb +1 -1
- data/test/service/process/tc_open.rb +1 -1
- data/test/service/process/tc_popen3.rb +13 -13
- data/test/tc_integration.rb +1 -1
- data/test/transport/compress/tc_none_compress.rb +1 -1
- data/test/transport/compress/tc_none_decompress.rb +1 -1
- data/test/transport/compress/tc_zlib_compress.rb +1 -1
- data/test/transport/compress/tc_zlib_decompress.rb +1 -1
- data/test/transport/kex/tc_dh.rb +2 -1
- data/test/transport/kex/tc_dh_gex.rb +1 -1
- data/test/transport/ossl/hmac/tc_hmac.rb +1 -1
- data/test/transport/ossl/hmac/tc_md5.rb +1 -1
- data/test/transport/ossl/hmac/tc_md5_96.rb +1 -1
- data/test/transport/ossl/hmac/tc_none.rb +1 -1
- data/test/transport/ossl/hmac/tc_sha1.rb +1 -1
- data/test/transport/ossl/hmac/tc_sha1_96.rb +1 -1
- data/test/transport/ossl/tc_buffer.rb +1 -1
- data/test/transport/ossl/tc_buffer_factory.rb +1 -1
- data/test/transport/ossl/tc_cipher_factory.rb +1 -1
- data/test/transport/ossl/tc_digest_factory.rb +1 -1
- data/test/transport/ossl/tc_hmac_factory.rb +1 -1
- data/test/transport/ossl/tc_key_factory.rb +1 -1
- data/test/transport/tc_algorithm_negotiator.rb +1 -1
- data/test/transport/tc_identity_cipher.rb +1 -1
- data/test/transport/tc_integration.rb +1 -1
- data/test/transport/tc_packet_stream.rb +1 -1
- data/test/transport/tc_session.rb +1 -1
- data/test/transport/tc_version_negotiator.rb +1 -1
- data/test/userauth/methods/tc_hostbased.rb +1 -1
- data/test/userauth/methods/tc_password.rb +1 -1
- data/test/userauth/methods/tc_publickey.rb +1 -1
- data/test/userauth/tc_agent.rb +1 -1
- data/test/userauth/tc_driver.rb +1 -1
- data/test/userauth/tc_integration.rb +15 -1
- data/test/userauth/tc_userkeys.rb +1 -1
- data/test/util/tc_buffer.rb +5 -5
- metadata +26 -6
@@ -1,7 +1,7 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
3
|
<title>Net::SSH Manual :: Chapter 3: Channels</title>
|
4
|
-
<link type="text/css" rel="stylesheet" href="manual.css" />
|
4
|
+
<link type="text/css" rel="stylesheet" href="stylesheets/manual.css" />
|
5
5
|
</head>
|
6
6
|
|
7
7
|
<body>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>
|
17
|
+
Net::SSH Version: <strong>0.9.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2005-01-11 21:39 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -110,36 +110,56 @@
|
|
110
110
|
|
111
111
|
<li>
|
112
112
|
<a href="chapter-5.html">
|
113
|
-
|
113
|
+
User Shells
|
114
114
|
</a>
|
115
115
|
|
116
116
|
<ol type="1">
|
117
117
|
|
118
118
|
<li><a href="chapter-5.html#s1">Introduction</a></li>
|
119
119
|
|
120
|
-
<li><a href="chapter-5.html#s2">
|
120
|
+
<li><a href="chapter-5.html#s2">Using Channels</a></li>
|
121
121
|
|
122
|
-
<li><a href="chapter-5.html#s3">
|
122
|
+
<li><a href="chapter-5.html#s3">Shell Service</a></li>
|
123
123
|
|
124
|
-
<li><a href="chapter-5.html#s4">
|
124
|
+
<li><a href="chapter-5.html#s4">SyncShell Service</a></li>
|
125
125
|
|
126
|
-
<li><a href="chapter-5.html#s5">
|
126
|
+
<li><a href="chapter-5.html#s5">Terminal Clients</a></li>
|
127
127
|
|
128
128
|
</ol>
|
129
129
|
</li>
|
130
130
|
|
131
131
|
<li>
|
132
132
|
<a href="chapter-6.html">
|
133
|
-
|
133
|
+
Port Forwarding
|
134
134
|
</a>
|
135
135
|
|
136
136
|
<ol type="1">
|
137
137
|
|
138
138
|
<li><a href="chapter-6.html#s1">Introduction</a></li>
|
139
139
|
|
140
|
-
<li><a href="chapter-6.html#s2"
|
140
|
+
<li><a href="chapter-6.html#s2">Local-to-Remote</a></li>
|
141
|
+
|
142
|
+
<li><a href="chapter-6.html#s3">Remote-to-Local</a></li>
|
141
143
|
|
142
|
-
<li><a href="chapter-6.html#
|
144
|
+
<li><a href="chapter-6.html#s4">Direct Channels</a></li>
|
145
|
+
|
146
|
+
<li><a href="chapter-6.html#s5">Remote-to-Local Handlers</a></li>
|
147
|
+
|
148
|
+
</ol>
|
149
|
+
</li>
|
150
|
+
|
151
|
+
<li>
|
152
|
+
<a href="chapter-7.html">
|
153
|
+
Using Proxies
|
154
|
+
</a>
|
155
|
+
|
156
|
+
<ol type="1">
|
157
|
+
|
158
|
+
<li><a href="chapter-7.html#s1">Introduction</a></li>
|
159
|
+
|
160
|
+
<li><a href="chapter-7.html#s2"><span class="caps">HTTP</span></a></li>
|
161
|
+
|
162
|
+
<li><a href="chapter-7.html#s3"><span class="caps">SOCKS</span></a></li>
|
143
163
|
|
144
164
|
</ol>
|
145
165
|
</li>
|
@@ -170,7 +190,17 @@
|
|
170
190
|
|
171
191
|
<div id="content">
|
172
192
|
|
173
|
-
|
193
|
+
<div class="top"><div class="prevnext">
|
194
|
+
|
195
|
+
<a href="chapter-2.html">Previous (2. Starting a Session)</a> |
|
196
|
+
|
197
|
+
<a href="index.html">Up</a>
|
198
|
+
|
199
|
+
| <a href="chapter-4.html">Next (4. Executing Commands)</a>
|
200
|
+
|
201
|
+
</div></div>
|
202
|
+
|
203
|
+
<h1>3. Channels</h1>
|
174
204
|
|
175
205
|
|
176
206
|
|
@@ -207,13 +237,13 @@
|
|
207
237
|
|
208
238
|
<p>The <code>loop</code> method is easy to invoke:</p>
|
209
239
|
|
240
|
+
<div class='figure'>
|
241
|
+
<span class='caption'>Session#loop [ruby]</span>
|
242
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
243
|
+
<span class="punct">...</span>
|
244
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
|
245
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
210
246
|
|
211
|
-
<pre>
|
212
|
-
Net::SSH.start( 'host' ) do |session|
|
213
|
-
...
|
214
|
-
session.loop
|
215
|
-
end
|
216
|
-
</pre>
|
217
247
|
<p>Incidentally, the <code>loop</code> method accepts an optional block, which if specified should return a “false” value when the loop should terminate. In the absense of a block, the loop will continue until there are no more open channels. Sometimes, however, you only want the loop to continue until some action occurs, at which time you then do some processing and then start the loop again.</p>
|
218
248
|
</div>
|
219
249
|
|
@@ -250,17 +280,17 @@
|
|
250
280
|
|
251
281
|
<p>Here is an example of opening a channel:</p>
|
252
282
|
|
283
|
+
<div class='figure'>
|
284
|
+
<span class='caption'>Opening a channel [ruby]</span>
|
285
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
286
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">open_channel</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">channel</span><span class="punct">|</span>
|
287
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">channel successfully opened... closing...</span><span class="punct">"</span>
|
288
|
+
<span class="ident">channel</span><span class="punct">.</span><span class="ident">close</span>
|
289
|
+
<span class="keyword">end</span>
|
253
290
|
|
254
|
-
<
|
255
|
-
|
256
|
-
session.open_channel do |channel|
|
257
|
-
puts "channel successfully opened... closing..."
|
258
|
-
channel.close
|
259
|
-
end
|
291
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
|
292
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
260
293
|
|
261
|
-
session.loop
|
262
|
-
end
|
263
|
-
</pre>
|
264
294
|
<p>Note the use of the <code>close</code> method for the channel. Just like most methods in the Net::SSH <span class="caps">API</span>, it does not immediately close the channel, but instead sends a close request to the server and returns. When the server responds that the channel has been closed, the framework will then call any final callbacks for the channel and then remove it.</p>
|
265
295
|
</div>
|
266
296
|
|
@@ -329,20 +359,19 @@
|
|
329
359
|
|
330
360
|
<p>Following is an example of registering callbacks on a channel:</p>
|
331
361
|
|
332
|
-
|
333
|
-
<
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
</pre>
|
362
|
+
<div class='figure'>
|
363
|
+
<span class='caption'>Registering callbacks on a channel [ruby]</span>
|
364
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
365
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">open_channel</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">channel</span><span class="punct">|</span>
|
366
|
+
<span class="ident">channel</span><span class="punct">.</span><span class="ident">on_close</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">ch</span><span class="punct">|</span>
|
367
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">channel closed successfully.</span><span class="punct">"</span>
|
368
|
+
<span class="keyword">end</span>
|
369
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">closing channel...</span><span class="punct">"</span>
|
370
|
+
<span class="ident">channel</span><span class="punct">.</span><span class="ident">close</span>
|
371
|
+
<span class="keyword">end</span>
|
372
|
+
|
373
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
|
374
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
346
375
|
</div>
|
347
376
|
|
348
377
|
|
@@ -404,6 +433,16 @@ operations.</p>
|
|
404
433
|
|
405
434
|
|
406
435
|
|
436
|
+
<div class="bottom"><div class="prevnext">
|
437
|
+
|
438
|
+
<a href="chapter-2.html">Previous (2. Starting a Session)</a> |
|
439
|
+
|
440
|
+
<a href="index.html">Up</a>
|
441
|
+
|
442
|
+
| <a href="chapter-4.html">Next (4. Executing Commands)</a>
|
443
|
+
|
444
|
+
</div></div>
|
445
|
+
|
407
446
|
|
408
447
|
</div>
|
409
448
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
3
|
<title>Net::SSH Manual :: Chapter 4: Executing Commands</title>
|
4
|
-
<link type="text/css" rel="stylesheet" href="manual.css" />
|
4
|
+
<link type="text/css" rel="stylesheet" href="stylesheets/manual.css" />
|
5
5
|
</head>
|
6
6
|
|
7
7
|
<body>
|
@@ -14,8 +14,8 @@
|
|
14
14
|
</div>
|
15
15
|
</td><td valign='middle' align='right'>
|
16
16
|
<div class="info">
|
17
|
-
Net::SSH Version: <strong>0.
|
18
|
-
Manual Last Updated: <strong>
|
17
|
+
Net::SSH Version: <strong>0.9.0</strong><br />
|
18
|
+
Manual Last Updated: <strong>2005-01-11 21:39 GMT</strong>
|
19
19
|
</div>
|
20
20
|
</td></tr>
|
21
21
|
</table>
|
@@ -110,36 +110,56 @@
|
|
110
110
|
|
111
111
|
<li>
|
112
112
|
<a href="chapter-5.html">
|
113
|
-
|
113
|
+
User Shells
|
114
114
|
</a>
|
115
115
|
|
116
116
|
<ol type="1">
|
117
117
|
|
118
118
|
<li><a href="chapter-5.html#s1">Introduction</a></li>
|
119
119
|
|
120
|
-
<li><a href="chapter-5.html#s2">
|
120
|
+
<li><a href="chapter-5.html#s2">Using Channels</a></li>
|
121
121
|
|
122
|
-
<li><a href="chapter-5.html#s3">
|
122
|
+
<li><a href="chapter-5.html#s3">Shell Service</a></li>
|
123
123
|
|
124
|
-
<li><a href="chapter-5.html#s4">
|
124
|
+
<li><a href="chapter-5.html#s4">SyncShell Service</a></li>
|
125
125
|
|
126
|
-
<li><a href="chapter-5.html#s5">
|
126
|
+
<li><a href="chapter-5.html#s5">Terminal Clients</a></li>
|
127
127
|
|
128
128
|
</ol>
|
129
129
|
</li>
|
130
130
|
|
131
131
|
<li>
|
132
132
|
<a href="chapter-6.html">
|
133
|
-
|
133
|
+
Port Forwarding
|
134
134
|
</a>
|
135
135
|
|
136
136
|
<ol type="1">
|
137
137
|
|
138
138
|
<li><a href="chapter-6.html#s1">Introduction</a></li>
|
139
139
|
|
140
|
-
<li><a href="chapter-6.html#s2"
|
140
|
+
<li><a href="chapter-6.html#s2">Local-to-Remote</a></li>
|
141
|
+
|
142
|
+
<li><a href="chapter-6.html#s3">Remote-to-Local</a></li>
|
141
143
|
|
142
|
-
<li><a href="chapter-6.html#
|
144
|
+
<li><a href="chapter-6.html#s4">Direct Channels</a></li>
|
145
|
+
|
146
|
+
<li><a href="chapter-6.html#s5">Remote-to-Local Handlers</a></li>
|
147
|
+
|
148
|
+
</ol>
|
149
|
+
</li>
|
150
|
+
|
151
|
+
<li>
|
152
|
+
<a href="chapter-7.html">
|
153
|
+
Using Proxies
|
154
|
+
</a>
|
155
|
+
|
156
|
+
<ol type="1">
|
157
|
+
|
158
|
+
<li><a href="chapter-7.html#s1">Introduction</a></li>
|
159
|
+
|
160
|
+
<li><a href="chapter-7.html#s2"><span class="caps">HTTP</span></a></li>
|
161
|
+
|
162
|
+
<li><a href="chapter-7.html#s3"><span class="caps">SOCKS</span></a></li>
|
143
163
|
|
144
164
|
</ol>
|
145
165
|
</li>
|
@@ -170,7 +190,17 @@
|
|
170
190
|
|
171
191
|
<div id="content">
|
172
192
|
|
173
|
-
|
193
|
+
<div class="top"><div class="prevnext">
|
194
|
+
|
195
|
+
<a href="chapter-3.html">Previous (3. Channels)</a> |
|
196
|
+
|
197
|
+
<a href="index.html">Up</a>
|
198
|
+
|
199
|
+
| <a href="chapter-5.html">Next (5. User Shells)</a>
|
200
|
+
|
201
|
+
</div></div>
|
202
|
+
|
203
|
+
<h1>4. Executing Commands</h1>
|
174
204
|
|
175
205
|
|
176
206
|
|
@@ -186,25 +216,25 @@
|
|
186
216
|
|
187
217
|
<p>Suppose, for example, that you wanted to run multiple “tail” commands on various logs on the remote machine, combining them all into the output on the client. Something like the following would suffice:</p>
|
188
218
|
|
219
|
+
<div class='figure'>
|
220
|
+
<span class='caption'>Running "tail" on multiple remote files [ruby]</span>
|
221
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="keyword">def </span><span class="method">do_tail</span><span class="punct">(</span> <span class="ident">session</span><span class="punct">,</span> <span class="ident">file</span> <span class="punct">)</span>
|
222
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">open_channel</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">channel</span><span class="punct">|</span>
|
223
|
+
<span class="ident">channel</span><span class="punct">.</span><span class="ident">on_data</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">ch</span><span class="punct">,</span> <span class="ident">data</span><span class="punct">|</span>
|
224
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">[</span><span class="expr">#{file}</span><span class="string">] -> </span><span class="expr">#{data}</span><span class="punct">"</span>
|
225
|
+
<span class="keyword">end</span>
|
226
|
+
<span class="ident">channel</span><span class="punct">.</span><span class="ident">exec</span> <span class="punct">"</span><span class="string">tail -f </span><span class="expr">#{file}</span><span class="punct">"</span>
|
227
|
+
<span class="keyword">end</span>
|
228
|
+
<span class="keyword">end</span>
|
229
|
+
|
230
|
+
<span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
231
|
+
<span class="ident">do_tail</span> <span class="ident">session</span><span class="punct">,</span> <span class="punct">"</span><span class="string">/var/log/messages</span><span class="punct">"</span>
|
232
|
+
<span class="ident">do_tail</span> <span class="ident">session</span><span class="punct">,</span> <span class="punct">"</span><span class="string">/var/log/XFree86.0.log</span><span class="punct">"</span>
|
233
|
+
<span class="ident">do_tail</span> <span class="ident">session</span><span class="punct">,</span> <span class="punct">"</span><span class="string">/var/log/tomcat/catalina.log</span><span class="punct">"</span>
|
234
|
+
<span class="ident">do_tail</span> <span class="ident">session</span><span class="punct">,</span> <span class="punct">"</span><span class="string">/var/log/mysql/mysql.err</span><span class="punct">"</span>
|
235
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
|
236
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
189
237
|
|
190
|
-
<pre>
|
191
|
-
def do_tail( session, file )
|
192
|
-
session.open_channel do |channel|
|
193
|
-
channel.on_data do |ch, data|
|
194
|
-
puts "[#{file}] -> #{data}"
|
195
|
-
end
|
196
|
-
channel.exec "tail -f #{file}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
Net::SSH.start( 'host' ) do |session|
|
201
|
-
do_tail session, "/var/log/messages"
|
202
|
-
do_tail session, "/var/log/XFree86.0.log"
|
203
|
-
do_tail session, "/var/log/tomcat/catalina.log"
|
204
|
-
do_tail session, "/var/log/mysql/mysql.err"
|
205
|
-
session.loop
|
206
|
-
end
|
207
|
-
</pre>
|
208
238
|
<p>As you can see, four different logs are tailed on four separate channels. Each channel registers an <code>on_data</code> callback (which simply displays the data it recieves, together with the name of the log file it came from). The <code>exec</code> method of the channel is then invoked, which simply sends the request to execute the process to the server, and then returns.</p>
|
209
239
|
|
210
240
|
<p>The <code>loop</code> method then blocks while packets and processed and callbacks are invoked, completing the program.</p>
|
@@ -228,33 +258,33 @@
|
|
228
258
|
|
229
259
|
<p>Consider the “bc” command. It is a command-line calculator that accepts expressions on <code>stdin</code> and writes the results to <code>stdout</code>. When it encounters the word <code>quit</code> on the input, it exits. Sounds like a great way to demonstrate the <code>process</code> service…</p>
|
230
260
|
|
261
|
+
<div class='figure'>
|
262
|
+
<span class='caption'>Using #process.open [ruby]</span>
|
263
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
231
264
|
|
232
|
-
<
|
233
|
-
|
265
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">process</span><span class="punct">.</span><span class="ident">open</span><span class="punct">(</span> <span class="punct">"</span><span class="string">bc</span><span class="punct">"</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">bc</span><span class="punct">|</span>
|
266
|
+
<span class="ident">dialog</span> <span class="punct">=</span> <span class="punct">[</span> <span class="punct">"</span><span class="string">5+5</span><span class="punct">",</span> <span class="punct">"</span><span class="string">7*12</span><span class="punct">",</span> <span class="punct">"</span><span class="string">sqrt(2.000000)</span><span class="punct">",</span> <span class="punct">"</span><span class="string">quit</span><span class="punct">"</span> <span class="punct">]</span>
|
234
267
|
|
235
|
-
|
236
|
-
|
268
|
+
<span class="ident">bc</span><span class="punct">.</span><span class="ident">on_success</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">p</span><span class="punct">|</span>
|
269
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">requesting result of </span><span class="expr">#{dialog.first}</span><span class="punct">"</span>
|
270
|
+
<span class="ident">p</span><span class="punct">.</span><span class="ident">puts</span> <span class="ident">dialog</span><span class="punct">.</span><span class="ident">shift</span>
|
271
|
+
<span class="keyword">end</span>
|
237
272
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
273
|
+
<span class="ident">bc</span><span class="punct">.</span><span class="ident">on_stdout</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">p</span><span class="punct">,</span><span class="ident">data</span><span class="punct">|</span>
|
274
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">--> </span><span class="expr">#{data}</span><span class="punct">"</span>
|
275
|
+
<span class="keyword">unless</span> <span class="ident">dialog</span><span class="punct">.</span><span class="ident">empty?</span>
|
276
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">requesting result of </span><span class="expr">#{dialog.first}</span><span class="punct">"</span>
|
277
|
+
<span class="ident">p</span><span class="punct">.</span><span class="ident">puts</span> <span class="ident">dialog</span><span class="punct">.</span><span class="ident">shift</span>
|
278
|
+
<span class="keyword">end</span>
|
279
|
+
<span class="keyword">end</span>
|
242
280
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
p.puts dialog.shift
|
248
|
-
end
|
249
|
-
end
|
281
|
+
<span class="ident">bc</span><span class="punct">.</span><span class="ident">on_exit</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">p</span><span class="punct">,</span> <span class="ident">status</span><span class="punct">|</span>
|
282
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">process finished with exit status: </span><span class="expr">#{status}</span><span class="punct">"</span>
|
283
|
+
<span class="keyword">end</span>
|
284
|
+
<span class="keyword">end</span>
|
250
285
|
|
251
|
-
|
252
|
-
puts "process finished with exit status: #{status}"
|
253
|
-
end
|
254
|
-
end
|
286
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
255
287
|
|
256
|
-
end
|
257
|
-
</pre>
|
258
288
|
<p>Notice the progression. First, the session itself is started. Then, while the session is active, the process is invoked (via <code>#process.open</code>). After we have a handle to the process (which is yielded to the block, in this case), we set up the callbacks on the process. These are reminiscent of, but different from, the callbacks that we set up on the channel itself in the previous section.</p>
|
259
289
|
|
260
290
|
<p>The following callbacks are defined for a process handle:</p>
|
@@ -311,39 +341,49 @@
|
|
311
341
|
|
312
342
|
<p>Here’s the previous “bc” example, rewritten to use <code>#popen3</code>:</p>
|
313
343
|
|
344
|
+
<div class='figure'>
|
345
|
+
<span class='caption'>Using #process.popen3 [ruby]</span>
|
346
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
314
347
|
|
315
|
-
<
|
316
|
-
Net::SSH.start( 'host' ) do |session|
|
348
|
+
<span class="ident">input</span><span class="punct">,</span> <span class="ident">output</span><span class="punct">,</span> <span class="ident">error</span> <span class="punct">=</span> <span class="ident">session</span><span class="punct">.</span><span class="ident">process</span><span class="punct">.</span><span class="ident">popen3</span><span class="punct">(</span> <span class="punct">"</span><span class="string">bc</span><span class="punct">"</span> <span class="punct">)</span>
|
317
349
|
|
318
|
-
|
350
|
+
<span class="punct">[</span> <span class="punct">"</span><span class="string">5+5</span><span class="punct">",</span> <span class="punct">"</span><span class="string">7*12</span><span class="punct">",</span> <span class="punct">"</span><span class="string">sqrt(2.000000)</span><span class="punct">"</span> <span class="punct">].</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">formula</span><span class="punct">|</span>
|
351
|
+
<span class="ident">input</span><span class="punct">.</span><span class="ident">puts</span> <span class="ident">formula</span>
|
352
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="expr">#{formula}</span><span class="string">=</span><span class="expr">#{output.read}</span><span class="punct">"</span>
|
353
|
+
<span class="keyword">end</span>
|
319
354
|
|
320
|
-
|
321
|
-
input.puts formula
|
322
|
-
puts "#{formula}=#{output.read}"
|
323
|
-
end
|
355
|
+
<span class="ident">input</span><span class="punct">.</span><span class="ident">puts</span> <span class="punct">"</span><span class="string">quit</span><span class="punct">"</span>
|
324
356
|
|
325
|
-
|
357
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
326
358
|
|
327
|
-
end
|
328
|
-
</pre>
|
329
359
|
<p>Much more concise, isn’t it? One caveat, though: there is no way to kill the process (unless the process can terminate itself, such as through the use of issuing bc’s “quit” command as used above) without closing the session. To remedy this, there is also a block version of popen3 that provides an explicit scope for the three data streams:</p>
|
330
360
|
|
361
|
+
<div class='figure'>
|
362
|
+
<span class='caption'>Transactional form of #process.popen3 [ruby]</span>
|
363
|
+
<div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
|
364
|
+
<span class="ident">session</span><span class="punct">.</span><span class="ident">process</span><span class="punct">.</span><span class="ident">popen3</span><span class="punct">(</span> <span class="punct">"</span><span class="string">bc</span><span class="punct">"</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">input</span><span class="punct">,</span> <span class="ident">output</span><span class="punct">,</span> <span class="ident">error</span><span class="punct">|</span>
|
365
|
+
<span class="punct">[</span> <span class="punct">"</span><span class="string">5+5</span><span class="punct">",</span> <span class="punct">"</span><span class="string">7*12</span><span class="punct">",</span> <span class="punct">"</span><span class="string">sqrt(2.000000)</span><span class="punct">"</span> <span class="punct">].</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">formula</span><span class="punct">|</span>
|
366
|
+
<span class="ident">input</span><span class="punct">.</span><span class="ident">puts</span> <span class="ident">formula</span>
|
367
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="expr">#{formula}</span><span class="string">=</span><span class="expr">#{output.read}</span><span class="punct">"</span>
|
368
|
+
<span class="keyword">end</span>
|
369
|
+
<span class="keyword">end</span>
|
370
|
+
<span class="keyword">end</span></pre></div></td></tr></table></div></div>
|
331
371
|
|
332
|
-
<pre>
|
333
|
-
Net::SSH.start( 'host' ) do |session|
|
334
|
-
session.process.popen3( "bc" ) do |input, output, error|
|
335
|
-
[ "5+5", "7*12", "sqrt(2.000000)" ].each do |formula|
|
336
|
-
input.puts formula
|
337
|
-
puts "#{formula}=#{output.read}"
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|
341
|
-
</pre>
|
342
372
|
<p>The three streams will be closed and process explicitly terminated when the block ends.</p>
|
343
373
|
</div>
|
344
374
|
|
345
375
|
|
346
376
|
|
377
|
+
<div class="bottom"><div class="prevnext">
|
378
|
+
|
379
|
+
<a href="chapter-3.html">Previous (3. Channels)</a> |
|
380
|
+
|
381
|
+
<a href="index.html">Up</a>
|
382
|
+
|
383
|
+
| <a href="chapter-5.html">Next (5. User Shells)</a>
|
384
|
+
|
385
|
+
</div></div>
|
386
|
+
|
347
387
|
|
348
388
|
</div>
|
349
389
|
|