Unicode C++
Unicode C++
Open a Custom SSH Channel Type
See more SSH Examples
Demonstrates the Chilkat Ssh.OpenCustomChannel method, which requests a channel whose application-defined type is supplied as the only argument. It returns the channel number, or -1 if the server rejects the channel. The server must implement that channel type.
Background: The SSH protocol allows vendor- and application-specific channel types beyond the standard
session and direct-tcpip kinds; by convention these carry an @domain suffix to avoid name collisions. This method is the escape hatch for talking to a server that implements such a type. On rejection, inspect ChannelOpenFailCode to learn why.Chilkat Unicode C++ Downloads
#include <CkSshW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Ssh.OpenCustomChannel method, which requests a custom SSH channel whose
// application-defined type is supplied as the only argument. It returns the channel number,
// or -1 if the server rejects the channel. The server must implement that channel type.
CkSshW ssh;
int sshPort = 22;
success = ssh.Connect(L"ssh.example.com",sshPort);
if (success == false) {
wprintf(L"%s\n",ssh.lastErrorText());
return;
}
// 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.
const wchar_t *password = L"mySshPassword";
success = ssh.AuthenticatePw(L"mySshLogin",password);
if (success == false) {
wprintf(L"%s\n",ssh.lastErrorText());
return;
}
// Request an application-defined channel type. The server must support it.
const wchar_t *channelType = L"my-custom-channel@example.com";
int channelNum = ssh.OpenCustomChannel(channelType);
if (channelNum < 0) {
wprintf(L"%s\n",ssh.lastErrorText());
return;
}
wprintf(L"Opened custom channel: %d\n",channelNum);
// The channel is used with the normal channel send, receive, EOF, CLOSE, and release methods.
ssh.Disconnect();
}