Sample code for 30+ languages & platforms
Dart

FTP Download File to a Stream

Demonstrates how to FTP download a file to a Chilkat stream.

Chilkat Dart Downloads

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

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

  final ftp = CkFtp2();

  ftp.hostname = 'my-ftp-server.com';
  ftp.port = 21;
  ftp.username = 'mFtpLogin';
  ftp.password = 'myFtpPassword';
  ftp.authTls = true;
  ftp.passive = true;

  // Connect and login to the FTP server using TLS.
  try {
    ftp.connect();
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Move to the sub-directory (from the FTP user's home directory) where the file is located.
  try {
    ftp.changeRemoteDir('temp');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Stream to this local file:
  final streamObj = CkStream();
  streamObj.sinkFile = 'c:/temp/qa_output/penguins2.jpg';

  try {
    ftp.getFileToStream('penguins2.jpg', streamObj);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  ftp.disconnect();

  print('Success.');
}