Sample code for 30+ languages & platforms
Dart

Start SFTP Keyboard-Interactive Authentication

See more SFTP Examples

Demonstrates the Chilkat SFtp.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts, which are answered with ContinueKeyboardAuth.

Background: Keyboard-interactive is the prompt-driven authentication method: rather than assuming a single password, the server sends one or more questions — a password, a one-time code, a security question — and the client answers each. This is how SFTP supports two-factor and other challenge-response schemes. The returned XML tells you exactly what to ask and whether to mask the input.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Demonstrates the SFtp.StartKeyboardAuth method, which begins keyboard-interactive
  // authentication.  The only argument is the login name.  It returns XML describing the server's
  // prompts, which are answered with ContinueKeyboardAuth.

  final sftp = CkSFtp();

  // Step 1: Connect the SSH transport.  Port 22 is the usual port.
  final port = 22;
  try {
    sftp.connect('sftp.example.com', port);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Begin keyboard-interactive authentication.  The returned XML describes the server's prompts.
  final String infoRequestXml;
  try {
    infoRequestXml = sftp.startKeyboardAuth('mySshLogin');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(infoRequestXml);

  // Answer the prompt(s) with ContinueKeyboardAuth, then call InitializeSftp.

  sftp.disconnect();
}