Sample code for 30+ languages & platforms
Dart

SCP Download File

See more SCP Examples

Demonstrates how to download a file using the SCP protocol (Secure Copy Protocol over SSH).

Chilkat Dart Downloads

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

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final ssh = CkSsh();

  // Hostname may be an IP address or hostname:
  final hostname = 'www.some-ssh-server.com';
  final port = 22;

  // Connect to an SSH server:
  try {
    ssh.connect(hostname, port);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Wait a max of 5 seconds when reading responses..
  ssh.idleTimeoutMs = 5000;

  // Authenticate using login/password:
  try {
    ssh.authenticatePw('myLogin', 'myPassword');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Once the SSH object is connected and authenticated, we use it
  // in our SCP object.
  final scp = CkScp();

  try {
    scp.useSsh(ssh);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final remotePath = 'test.txt';
  final localPath = '/home/bob/test.txt';
  try {
    scp.downloadFile(remotePath, localPath);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('SCP download file success.');

  // Disconnect
  ssh.disconnect();
}