Dev Tunnels SSH TCP Library
Includes SshClient
and SshServer
convenience classes for establishing SSH
sessions over TCP, and the PortForwardingService
class that enables forwarding
TCP ports between client and server.
Examples
Forward from a server port to a client port
const config = new SshSessionConfiguration();
config.addService(PortForwardingService);
const client = new SshClient(config);
const session: SshClientSession = await client.openSession(host, port);
session.onAuthenticating((e) => { ... });
if (!(await session.authenticate(credentials))) {
throw new Error('Authentication failed.');
}
const pfs = session.activateService(PortForwardingService);
const forwarder: RemotePortForwarder = await pfs.forwardFromRemotePort('::', remotePort);
forwarder.dispose();
Stream to a server port
const session: SshClientSession = ...
const pfs = session.activateService(PortForwardingService);
const stream: SshStream = await pfs.streamToRemotePort('localhost', remotePort);
Browser compatibility
This package has limited capabilities when running in a browser. Obviously a browser
cannot access local TCP ports. However, it is possible to stream to/from
server ports. The streamFromRemotePort()
and streamToRemotePort()
methods are
validated working in a browser environment.