File: Session.html

package info (click to toggle)
libnet-ssh-ruby 1.0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,180 kB
  • ctags: 2,327
  • sloc: ruby: 10,321; makefile: 52
file content (488 lines) | stat: -rw-r--r-- 20,836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Net::SSH::Session</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Net::SSH::Session</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/net/ssh/session_rb.html">
                lib/net/ssh/session.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Encapsulates a single session (connection) to a server via <a
href="../SSH.html">SSH</a>.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000304">close</a>&nbsp;&nbsp;
      <a href="#M000307">loop</a>&nbsp;&nbsp;
      <a href="#M000308">method_missing</a>&nbsp;&nbsp;
      <a href="#M000303">new</a>&nbsp;&nbsp;
      <a href="#M000305">open?</a>&nbsp;&nbsp;
      <a href="#M000306">open_channel</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">connection</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The underlying connection

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">host</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The name of the host that this session is connected to.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">options</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The hash of options that were used to establish this session.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">registry</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The dependency-injection registry used by this session.

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000303" class="method-detail">
        <a name="M000303"></a>

        <div class="method-heading">
          <a href="#M000303" class="method-signature">
          <span class="method-name">new</span><span class="method-args">( *args ) {|self| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a new <a href="../SSH.html">SSH</a> session. This method
polymorphically accepts a variable number of parameters, as follows:
</p>
<ul>
<li>1 parameter: must be the hostname to connect to.

</li>
<li>2 parameters: must be the hostname, and either the port (as an integer) or
the username to connect as.

</li>
<li>3 parameters: must be the hostname, and either the port (as an integer) and
username, or the username and the password.

</li>
<li>4 parameters: must be the hostname, port, username, and password.

</li>
</ul>
<p>
Any scenario above that omits the username assumes that the USER
environment variable is set to the user&#8217;s name. Any scenario above
that omits the password assumes that the user will log in without a
password (ie, using a public key). Any scenario above that omits the port
number assumes a port number of 22 (the default for <a
href="../SSH.html">SSH</a>).
</p>
<p>
Any of the above scenarios may also accept a Hash as the last parameter,
specifying a list of additional options to be used to initialize the
session. (See Net::SSH::Session.add_options).
</p>
<p>
Alternatively, named parameters may be used, in which case the first
parameter is positional and is always the host to connect to, following
which you may specify any of the following named parameters (as symbols):
</p>
<ul>
<li>:port

</li>
<li>:username

</li>
<li>:password

</li>
</ul>
<p>
Any additional parameters are treated as options that configure how the
connection behaves.
</p>
<p>
Allowed options are:
</p>
<ul>
<li>:keys (the list of filenames identifying the user&#8217;s keys)

</li>
<li>:host_keys (the list of filenames identifying the host&#8217;s keys)

</li>
<li>:auth_methods (a list of authentication methods to use)

</li>
<li>:crypto_backend (defaults to :ossl, and specifies the cryptography backend
to use)

</li>
<li>:registry_options (a hash of options to use when creating the registry)

</li>
<li>:container (the registry to use. If not specified, a new registry will be
created)

</li>
<li>:verbose (how verbose the logging output should be. Defaults to :warn).

</li>
<li>:log (the name of the file, or the IO object, to which messages will be
logged. Defaults to STDERR.)

</li>
</ul>
<p>
Also, any options recognized by <a
href="Transport/Session.html">Net::SSH::Transport::Session</a> may be
given, and will be passed through to initialize the transport session.
</p>
<p>
If a block is given to this method, then it is called with the new session
object. The session object is then closed when the block terminates. If a
block is not given, then the session object is returned (and must be closed
explicitly).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000303-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000303-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/session.rb, line 93</span>
 93:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
 94:         <span class="ruby-ivar">@open</span> = <span class="ruby-keyword kw">false</span>
 95:         <span class="ruby-identifier">process_arguments</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
 96: 
 97:         <span class="ruby-ivar">@registry</span>.<span class="ruby-identifier">define</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span>
 98:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">crypto_backend</span> { <span class="ruby-ivar">@crypto_backend</span> }
 99:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">transport_host</span> { <span class="ruby-ivar">@host</span> }
100:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">transport_options</span> { <span class="ruby-ivar">@options</span> }
101: 
102:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">userauth_keys</span> { <span class="ruby-ivar">@keys</span> }
103:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">userauth_host_keys</span> { <span class="ruby-ivar">@host_keys</span> }
104:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">userauth_method_order</span> { <span class="ruby-ivar">@auth_methods</span> }
105: 
106:           <span class="ruby-comment cmt"># Register myself with the registry, so that other services may</span>
107:           <span class="ruby-comment cmt"># access me.</span>
108:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">session</span>( <span class="ruby-identifier">:pipeline</span> =<span class="ruby-operator">&gt;</span> [] ) { <span class="ruby-keyword kw">self</span> }
109: 
110:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">prompter</span> <span class="ruby-keyword kw">do</span>
111:             <span class="ruby-identifier">require</span> <span class="ruby-value str">'net/ssh/util/prompter'</span>
112:             <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Util</span><span class="ruby-operator">::</span><span class="ruby-constant">Prompter</span>.<span class="ruby-identifier">new</span>
113:           <span class="ruby-keyword kw">end</span>
114: 
115:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">require</span> <span class="ruby-value str">'net/ssh/transport/services'</span>, <span class="ruby-value str">&quot;Net::SSH::Transport&quot;</span>
116:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">require</span> <span class="ruby-value str">'net/ssh/connection/services'</span>, <span class="ruby-value str">&quot;Net::SSH::Connection&quot;</span>
117:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">require</span> <span class="ruby-value str">'net/ssh/userauth/services'</span>, <span class="ruby-value str">&quot;Net::SSH::UserAuth&quot;</span>
118: 
119:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">require</span> <span class="ruby-value str">'net/ssh/service/services'</span>, <span class="ruby-value str">&quot;Net::SSH::Service&quot;</span>
120:         <span class="ruby-keyword kw">end</span>
121: 
122:         <span class="ruby-identifier">userauth</span> = <span class="ruby-ivar">@registry</span>[<span class="ruby-identifier">:userauth</span>][<span class="ruby-identifier">:driver</span>]
123:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">userauth</span>.<span class="ruby-identifier">authenticate</span>( <span class="ruby-value str">&quot;ssh-connection&quot;</span>, <span class="ruby-ivar">@username</span>, <span class="ruby-ivar">@password</span> )
124:           <span class="ruby-ivar">@open</span> = <span class="ruby-keyword kw">true</span>
125:           <span class="ruby-ivar">@connection</span> = <span class="ruby-ivar">@registry</span>[<span class="ruby-identifier">:connection</span>][<span class="ruby-identifier">:driver</span>]
126:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
127:             <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
128:             <span class="ruby-identifier">close</span>
129:           <span class="ruby-keyword kw">end</span>
130:         <span class="ruby-keyword kw">else</span>
131:           <span class="ruby-ivar">@registry</span>[<span class="ruby-identifier">:transport</span>][<span class="ruby-identifier">:session</span>].<span class="ruby-identifier">close</span>
132:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">AuthenticationFailed</span>, <span class="ruby-ivar">@username</span>
133:         <span class="ruby-keyword kw">end</span>
134:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000304" class="method-detail">
        <a name="M000304"></a>

        <div class="method-heading">
          <a href="#M000304" class="method-signature">
          <span class="method-name">close</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Closes the session, if it is open. If it is not open, this does nothing.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000304-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000304-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/session.rb, line 138</span>
138:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
139:         <span class="ruby-ivar">@registry</span>[<span class="ruby-identifier">:transport</span>][<span class="ruby-identifier">:session</span>].<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@open</span>
140:         <span class="ruby-ivar">@open</span> = <span class="ruby-keyword kw">false</span>
141:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000307" class="method-detail">
        <a name="M000307"></a>

        <div class="method-heading">
          <a href="#M000307" class="method-signature">
          <span class="method-name">loop</span><span class="method-args">( &amp;block )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Enters the main communication loop. This processes events occuring over the
channel. If a block is given, the loop will continue for as long as the
block returns <tt>true</tt>. Otherwise, the loop continues until there are
no more open channels. (See <a
href="Connection/Driver.html#M000210">Net::SSH::Connection::Driver#loop</a>).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000307-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000307-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/session.rb, line 162</span>
162:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">loop</span>( <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
163:         <span class="ruby-identifier">sanity_check</span>
164:         <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">loop</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
165:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000308" class="method-detail">
        <a name="M000308"></a>

        <div class="method-heading">
          <a href="#M000308" class="method-signature">
          <span class="method-name">method_missing</span><span class="method-args">( sym, *args, &amp;block )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Provides convenient access to services that have been registered with the
session, such as &quot;process&quot; and &quot;forward&quot;.
</p>
<p>
Usage:
</p>
<pre>
  session.forward.local(...)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000308-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000308-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/session.rb, line 173</span>
173:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>( <span class="ruby-identifier">sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
174:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@registry</span>[<span class="ruby-identifier">:services</span>].<span class="ruby-identifier">has_key?</span>( <span class="ruby-identifier">sym</span> )
175:           <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@registry</span>[<span class="ruby-identifier">:services</span>][ <span class="ruby-identifier">sym</span> ]
176:         <span class="ruby-keyword kw">else</span>
177:           <span class="ruby-keyword kw">super</span>
178:         <span class="ruby-keyword kw">end</span>
179:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000305" class="method-detail">
        <a name="M000305"></a>

        <div class="method-heading">
          <a href="#M000305" class="method-signature">
          <span class="method-name">open?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns <tt>true</tt> if the session is currently open.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000305-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000305-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/session.rb, line 144</span>
144:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">open?</span>
145:         <span class="ruby-ivar">@open</span>
146:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000306" class="method-detail">
        <a name="M000306"></a>

        <div class="method-heading">
          <a href="#M000306" class="method-signature">
          <span class="method-name">open_channel</span><span class="method-args">( type=&quot;session&quot;, data=nil, &amp;block )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Opens a new communication channel over the current connection. This returns
immediately. The block will be invoked when then the channel has been
opened. (See <a
href="Connection/Driver.html#M000203">Net::SSH::Connection::Driver#open_channel</a>).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000306-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000306-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/session.rb, line 151</span>
151:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">open_channel</span>( <span class="ruby-identifier">type</span>=<span class="ruby-value str">&quot;session&quot;</span>, <span class="ruby-identifier">data</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
152:         <span class="ruby-identifier">sanity_check</span>
153:         <span class="ruby-identifier">channel</span> = <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">open_channel</span>( <span class="ruby-identifier">type</span>, <span class="ruby-identifier">data</span> )
154:         <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_confirm_open</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
155:         <span class="ruby-identifier">channel</span>
156:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>