Sample code for 30+ languages & platforms
VB.NET

Request an SSH Subsystem

See more SSH Examples

Demonstrates the Chilkat Ssh.SendReqSubsystem method, which requests a predefined subsystem on a session channel. The first argument is the channel number and the second is the subsystem name. This example requests the sftp subsystem.

Background: A subsystem is a named service the server exposes over a channel instead of a shell command — sftp is the familiar example, and netconf is common on network devices. After acceptance, the channel carries that protocol's data, exchanged with the ordinary channel send and receive methods. If the server rejects the subsystem, the channel normally stays open and can be reused for another request.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Demonstrates the Ssh.SendReqSubsystem method, which requests a predefined subsystem on a
'  session channel.  The 1st argument is the channel number and the 2nd is the subsystem name.

Dim ssh As New Chilkat.Ssh

Dim sshPort As Integer = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = False) Then
    Debug.WriteLine(ssh.LastErrorText)
    Exit Sub
End If


'  Normally you would not hard-code the password in source.  You should instead obtain it
'  from an interactive prompt, environment variable, or a secrets vault.
Dim password As String = "mySshPassword"

success = ssh.AuthenticatePw("mySshLogin",password)
If (success = False) Then
    Debug.WriteLine(ssh.LastErrorText)
    Exit Sub
End If


'  Open a session channel.  A negative return value indicates failure.
Dim channelNum As Integer = ssh.OpenSessionChannel()
If (channelNum < 0) Then
    Debug.WriteLine(ssh.LastErrorText)
    Exit Sub
End If


'  Request the "sftp" subsystem.  A True return means the server accepted the request;
'  subsequent protocol data is exchanged with the normal channel send and receive methods.
success = ssh.SendReqSubsystem(channelNum,"sftp")
If (success = False) Then
    Debug.WriteLine(ssh.LastErrorText)
    Exit Sub
End If

Debug.WriteLine("Subsystem request accepted.")

ssh.Disconnect()