aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/doc/src/ssh_connection.xml
blob: 499cbbeabe27bbadd5a9491854c37c352d9dce55 (plain) (blame)
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
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2008</year>
      <year>2008</year>
      <holder>Ericsson AB, All Rights Reserved</holder>
    </copyright>
    <legalnotice>
  The contents of this file are subject to the Erlang Public License,
  Version 1.1, (the "License"); you may not use this file except in
  compliance with the License. You should have received a copy of the
  Erlang Public License along with this software. If not, it can be
  retrieved online at http://www.erlang.org/.

  Software distributed under the License is distributed on an "AS IS"
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  the License for the specific language governing rights and limitations
  under the License.

  The Initial Developer of the Original Code is Ericsson AB.
    </legalnotice>

    <title>ssh_connection</title>
    <prepared>Ingela Anderton Andin</prepared>
    <responsible></responsible>
    <docno></docno>
    <approved></approved>
    <checked></checked>
    <date></date>
    <rev></rev>
  </header>
  <module>ssh_connection</module>
  <modulesummary>This module provides an API to the ssh connection protocol.
  </modulesummary>
  <description>
    <p>This module provides an API to the ssh connection protocol.
    Not all features of the connection protocol are officially supported yet.
    Only the ones supported are documented here.</p>
  </description>

   <section>
    <title>COMMON DATA TYPES </title>
    <p>Type definitions that are used more than once in this module and/or
    abstractions to indicate the intended use of the data type:</p>
    
    <p><c>boolean() = true | false </c></p>
    <p><c>string() = list of ASCII characters</c></p>
    <p><c>timeout() =  infinity | integer() - in milliseconds.</c></p>
    <p><c>ssh_connection_ref() - opaque to the user returned by
    ssh:connect/3 or sent to a ssh channel processes</c></p>
    <p><c>ssh_channel_id() = integer() </c></p>
    <p><c>ssh_data_type_code() = 1 ("stderr") | 0 ("normal") are
    currently valid values see RFC 4254 section 5.2.</c></p>
    <p><c>ssh_request_status() = success | failure</c></p>
   </section>

   <section>
     <title>MESSAGES SENT TO CHANNEL PROCESSES</title>
     
     <p>As a result of the ssh connection protocol messages on the form
     <c><![CDATA[{ssh_cm, ssh_connection_ref(), term()}]]></c>
     will be sent to a channel process. The term will contain
     information regarding the ssh connection protocol event,
     for details see the ssh channel behavior callback <seealso
     marker="ssh_channel">handle_ssh_msg/2 </seealso> </p>
   </section>
   
 <funcs>
   
   <func>
     <name>adjust_window(ConnectionRef, ChannelId, NumOfBytes) -> ok</name>
     <fsummary>Adjusts the ssh flowcontrol window. </fsummary>
     <type>
       <v> ConnectionRef = ssh_connection_ref() </v>
       <v> ChannelId = ssh_channel_id() </v>
       <v> NumOfBytes = integer()</v>
     </type>
      <desc>
	<p>Adjusts the ssh flowcontrol window. </p>
	
	<note><p>This will be taken care of by the ssh_channel
	behavior when the callback <seealso marker="ssh_channel">
	handle_ssh_msg/2 </seealso> has returned after processing a
	{ssh_cm, ssh_connection_ref(), {data, ssh_channel_id(),
	ssh_data_type_code(), binary()}}
	message, and should normally not be called explicitly.</p></note>
      </desc>
   </func>
   
   <func>
     <name>close(ConnectionRef, ChannelId) -> ok</name>
     <fsummary>Sends a close message on the channel <c>ChannelId</c>. </fsummary>
     <type>
       <v> ConnectionRef = ssh_connection_ref() </v>
       <v> ChannelId = ssh_channel_id()</v>
     </type>
     <desc>
       <p>Sends a close message on the channel <c>ChannelId</c>
       </p>

       <note><p>This function will be called by the ssh channel
       behavior when the channel is terminated see <seealso
       marker="ssh_channel"> ssh_channel(3) </seealso> and should
       normally not be called explicitly.</p></note>
     </desc>
   </func>
   
   <func>
     <name>exec(ConnectionRef, ChannelId, Command, TimeOut) -> ssh_request_status()  </name>
     <fsummary>Will request that the server start the
     execution of the given command.  </fsummary>
     <type>
       <v> ConnectionRef = ssh_connection_ref() </v>
       <v> ChannelId = ssh_channel_id()</v>
       <v> Command = string()</v>
       <v>Timeout = timeout() </v>
     </type>
     <desc>
       <p>Will request that the server start the execution of the
       given command, the result will be received as:</p>

       <taglist>
	 <tag><c> N X {ssh_cm,
	 ssh_connection_ref(), {data, ssh_channel_id(), ssh_data_type_code(),
	 binary() = Data}} </c></tag>
	 <item>The result of executing the command may be only one line
	 or thousands of lines depending on the command.</item>

	 <tag><c> 1 X {ssh_cm, ssh_connection_ref(), {eof, ssh_channel_id()}}</c></tag>
	 <item>Indicates that no more data will be sent.</item>

	 <tag><c>0 or 1 X {ssh_cm,
	 ssh_connection_ref(), {exit_signal,
	 ssh_channel_id(), string() = ExitSignal, string() = ErrorMsg, string() = LanguageString}}</c></tag>
	 <item>Not all systems send signals. For details on valid string
	 values see RFC 4254 section 6.10 </item>
	 
	  <tag><c>0 or 1 X {ssh_cm, ssh_connection_ref(), {exit_status,
	  ssh_channel_id(), integer() = ExitStatus}}</c></tag>
	  <item>It is recommended by the <c>ssh connection protocol</c> that this
	  message shall be sent, but that may not always be the case.</item>

	  <tag><c> 1 X {ssh_cm, ssh_connection_ref(),
	  {closed, ssh_channel_id()}}</c></tag>
	  <item>Indicates that the ssh channel started for the
	  execution of the command has now been shutdown.</item>
       </taglist>
       
       <p> These message should be handled by the
       client. The <seealso marker="ssh_channel">ssh channel
       behavior</seealso> can be used when writing a client.
       </p>
     </desc>
   </func>


   <func>
     <name>exit_status(ConnectionRef, ChannelId, Status) -> ok</name>
     <fsummary>Sends the exit status of a command to the client.</fsummary>
     <type>
       <v> ConnectionRef = ssh_connection_ref() </v>
       <v> ChannelId = ssh_channel_id()</v>
       <v> Status = integer()</v>
     </type>
     <desc>
       <p>Sends the exit status of a command to the client.</p>
     </desc>
 </func>
   
     <func>
       <name>reply_request(ConnectionRef, WantReply, Status, CannelId) -> ok</name>
       <fsummary>Send status replies to requests that want such replies. </fsummary>
      <type>
	<v> ConnectionRef = ssh_connection_ref() </v>
	<v> WantReply =  boolean()</v>
	<v> Status = ssh_request_status() </v>
	<v> ChannelId = ssh_channel_id()</v>
      </type>
      <desc>
	<p>Sends status replies to requests where the requester has
	stated that they want a status report e.i .<c> WantReply = true</c>,
	if <c> WantReply</c> is false calling this function will be a
	"noop". Should be called after handling an ssh connection
	protocol message containing a <c>WantReply</c> boolean
	value. See the ssh_channel behavior callback <seealso
	marker="ssh_channel"> handle_ssh_msg/2 </seealso>
	</p>
      </desc>
     </func>
    
     <func>
       <name>send(ConnectionRef, ChannelId, Data) -></name>
       <name>send(ConnectionRef, ChannelId, Data, Timeout) -></name>
       <name>send(ConnectionRef, ChannelId, Type, Data) -></name>
       <name>send(ConnectionRef, ChannelId, Type, Data, TimeOut) ->
       ok | {error, timeout}</name>
       <fsummary>Sends channel data </fsummary>
       <type>
	<v> ConnectionRef = ssh_connection_ref() </v>
	<v> ChannelId = ssh_channel_id()</v>
	<v> Data = binary()</v>
	<v> Type = ssh_data_type_code()</v>
	<v> Timeout = timeout()</v>
       </type>
       <desc>
	 <p>Sends channel data. 
	 </p>
       </desc>
     </func>
     
     <func>
       <name>send_eof(ConnectionRef, ChannelId) -> ok </name>
       <fsummary>Sends eof on the channel <c>ChannelId</c>.  </fsummary>
       <type>
	<v> ConnectionRef = ssh_connection_ref() </v>
	<v> ChannelId = ssh_channel_id()</v>
       </type>
       <desc>
	 <p>Sends eof on the channel <c>ChannelId</c>.
	 </p>
       </desc>
     </func>

     <func>
       <name>session_channel(ConnectionRef, Timeout) -> </name>
       <name>session_channel(ConnectionRef, InitialWindowSize,
       MaxPacketSize, Timeout) -> {ok, ssh_channel_id()} | {error, Reason}</name>
       <fsummary>Opens a channel for a ssh session. A session is a
       remote execution of a program. The program may be a shell, an
       application, a system command, or some built-in subsystem. </fsummary>
       <type>
	 <v> ConnectionRef = ssh_connection_ref()</v>
	 <v> InitialWindowSize = integer() </v>
	 <v> MaxPacketSize = integer() </v>
	 <v> Timeout = timeout()</v>
	 <v> Reason = term() </v>
       </type>
       <desc>
	 <p>Opens a channel for a ssh session. A session is a
	 remote execution of a program. The program may be a shell, an
	 application, a system command, or some built-in subsystem.
	</p>
       </desc>
     </func>

    <func>
      <name>setenv(ConnectionRef, ChannelId, Var, Value, TimeOut) -> ssh_request_status()</name>
      <fsummary> Environment variables may be passed to the
      shell/command to be started later.</fsummary>
      <type>
	<v> ConnectionRef = ssh_connection_ref() </v>
	<v> ChannelId = ssh_channel_id()</v>
	<v> Var = string()</v>
	<v> Value = string()</v>
	<v> Timeout = timeout()</v>
      </type>
      <desc>
	<p> Environment variables may be passed to the shell/command to be
	started later.
	</p>
      </desc>
    </func>
    
    <func>
      <name>shell(ConnectionRef, ChannelId) -> ssh_request_status()
      </name>
      <fsummary> Will request that the user's default shell (typically
      defined in /etc/passwd in UNIX systems) be started at the other
      end. </fsummary>
       <type>
	 <v> ConnectionRef = ssh_connection_ref() </v>
	 <v> ChannelId = ssh_channel_id()</v>
       </type>
       <desc>
	 <p> Will request that the user's default shell (typically
	 defined in /etc/passwd in UNIX systems) be started at the
	 other end. 
	 </p>
       </desc>
    </func>

    <func>
      <name>subsystem(ConnectionRef, ChannelId, Subsystem, Timeout) -> ssh_request_status()</name>
      <fsummary>  </fsummary>
       <type>
	 <v> ConnectionRef = ssh_connection_ref() </v>
	 <v> ChannelId = ssh_channel_id()</v>
	 <v> Subsystem = string()</v>
	 <v> Timeout = timeout()</v>
       </type>
       <desc>
	 <p> Sends a request to execute a predefined subsystem.
	 </p>
       </desc>
    </func>
    
  </funcs>
  
</erlref>