diff --git a/src/connect.ts b/src/connect.ts index 16de53d..dc69e76 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -102,6 +102,22 @@ export async function calculateActualConfig(config: FileSystemConfig): Promise { config = (await calculateActualConfig(config))!; if (!config) return null; + if (config.hop) { + const hop = loadConfigs().find(c => c.name === config.hop); + if (!hop) throw new Error(`A SSH FS configuration with the name '${config.hop}' doesn't exist`); + const ssh = await createSSH(hop); + if (!ssh) return null; + return new Promise((resolve, reject) => { + ssh.forwardOut('localhost', 0, config.host!, config.port || 22, (err, channel) => { + if (err) { + err.message = `Couldn't connect through the hop:\n${err.message}`; + return reject(err); + } + channel.once('close', () => ssh.destroy()); + resolve(channel); + }); + }); + } switch (config.proxy && config.proxy.type) { case null: case undefined: diff --git a/src/manager.ts b/src/manager.ts index ebcd608..d848ec4 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -29,6 +29,7 @@ export interface FileSystemConfig extends ConnectConfig { putty?: string | boolean; proxy?: ProxyConfig; privateKeyPath?: string; + hop?: string; } export enum ConfigStatus {