testPasswordLessSshConnection method

Future<bool> testPasswordLessSshConnection(
  1. String username,
  2. InternetAddress ip, {
  3. bool addHostToKnownHosts = true,
})

Checks if the device is reachable via ssh

Implementation

Future<bool> testPasswordLessSshConnection(
  String username,
  InternetAddress ip, {
  bool addHostToKnownHosts = true,
}) async {
  final String sshTarget = ip.sshTarget(username);

  final spinner = interaction.spinner(
    inProgressMessage: 'Testing SSH connection',
    doneMessage: 'Testing SSH connection completed',
    failedMessage: 'Testing SSH connection failed',
  );

  final result = await processRunner.runCommand(
    hostPlatform.sshCommand(
      ipv6: ip.type == InternetAddressType.IPv6,
      sshTarget: sshTarget,
      command: 'echo "Test SSH Connection"',
      addHostToKnownHosts: addHostToKnownHosts,
      lastCommand: true,
    ),
    parseResult: (result) {
      return true;
    },
    parseFail: (e, s) {
      logger.info(
          'Something went wrong while trying to connect to the device via ssh.');
      logger.detail(
        'Exception: $e \nStack: $s',
      );
      return false;
    },
    spinner: spinner,
    label: 'testPasswordLessSshConnection',
    logger: logger,
  );

  return result ?? false;
}