getSSHClient method

String getSSHClient(
  1. List<String> arguments,
  2. ResponseCallback response,
  3. VoidCallback done,
  4. String keyApp, {
  5. int termWidth = 80,
  6. int termHeight = 25,
})

Implementation

String getSSHClient(List<String> arguments, ResponseCallback response,
    VoidCallback done, String keyApp,
    {int termWidth = 80, int termHeight = 25}) {
  final argParser = ArgParser()
    ..addOption('login', abbr: 'l')
    ..addOption('identity', abbr: 'i')
    ..addOption('password')
    ..addOption('tunnel')
    ..addOption('kex')
    ..addOption('key')
    ..addOption('cipher')
    ..addOption('mac')
    ..addFlag('debug')
    ..addFlag('trace')
    ..addFlag('agentForwarding', abbr: 'A');

  final ArgResults args = argParser.parse(arguments);

  identity = null;
  forwardChannel = null;

  if (args.rest.length != 1) {
    print('usage: ssh -l login url [args]');
    print(argParser.usage);
    return "usage: ssh -l login url [args]";
  }

  String host = args.rest.first,
      login = args['login'],
      identityFile = args['identity'],
      tunnel = args['tunnel'];

  if (login == null || login.isEmpty) {
    print('no login specified');
    return "no login specified";
  }

  if (host != null && host.split(":").length == 1) {
    host = host + ":22";
  }

  if (tunnel != null && tunnel.split(':').length != 2) {
    print('tunnel target should be specified host:port');
    return "tunnel target should be specified host:port";
  }

  applyCipherSuiteOverrides(
      args['kex'], args['key'], args['cipher'], args['mac']);

  try {
    this.sshClientStatus.sshClient = SSHClient(
      hostport: parseUri(host),
      login: login,
      print: print,
      termWidth: termWidth,
      termHeight: termHeight,
      termvar: Platform.environment['TERM'] ?? 'xterm',
      agentForwarding: args['agentForwarding'],
      debugPrint: args['debug'] ? print : null,
      tracePrint: args['trace'] ? print : null,
      getPassword: ((args['password'] != null)
          ? () => utf8.encode(args['password'])
          : null),
      response: response,
      loadIdentity: () {
        if (identity == null && identityFile != null) {
          identity = parsePem(File(identityFile).readAsStringSync());
        }
        return identity;
      },
      disconnected: done,
      startShell: tunnel == null,
      success: (null),
    );
  } catch (error, stacktrace) {
    print('ssh: exception: $error: $stacktrace');
    return error;
  }

  return "true";
}