SSH.OpenChannel - charonn0/RB-libssh2 GitHub Wiki
SSH.OpenChannel
Method signatures
Protected Function OpenChannel(Session As SSH.Session, Type As String = "session", Message As String = "") As SSH.Channel
Protected Function OpenChannel(URL As String, KnownHostList As FolderItem = Nil, AddHost As Boolean = False) As SSH.Channel
OpenChannel(SSH.Session, String, String)
| Name | Type | Comment |
|---|---|---|
Session |
SSH.Session | The active session to open a channel through. |
Type |
String | Optional. The SSH subsystem that the channel will be used for. |
Message |
String | Optional. The subsystem-defined message to send. |
OpenChannel(String, FolderItem, Boolean)
| Name | Type | Comment |
|---|---|---|
URL |
String | A fully qualified URL to open as an SSH channel. |
KnownHostList |
FolderItem | Optional. A list of known hosts to check the server against. |
AddHost |
Boolean | Optional. Whether to add the server to the list of known hosts. |
Return value
On success returns an instance of SSH.Channel. On error either returns Nil or raises an exception (see remarks.)
Remarks
This convenience method opens a generic SSH channel to the remote server.
Error handling
OpenChannel(SSH.Session, String, String)
If an error occurs while opening the channel then the return value will be Nil and the error details are stored in the Session parameter (Session.LastError, etc.)
OpenChannel(String, FolderItem, Boolean)
In an error occurs while establishing a new session and opening the channel then an SSHException will be raised.
Example
This example starts a command ("uptime") on the remote machine and reads from its StdOut stream:
Dim sh As SSH.Channel = SSH.OpenChannel("ssh://user:[email protected]/")
Call sh.Execute("uptime")
Dim result As String
Do Until sh.EOF
If sh.PollReadable() Then
result = result + sh.Read(sh.BytesReadable, 0)
End If
Loop
sh.Close
See also
- Channel.Open method