Sample code for 30+ languages & platforms
Dart

Download Multiple Files Matching Pattern

See more FTP Examples

The MGetFiles method can be called to download all files matching a wildcarded filename pattern.

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 ftp = CkFtp2();

  ftp.hostname = 'ftp.example.com';
  ftp.username = 'myUsername';
  ftp.password = 'myPassword';
  ftp.port = 21;
  ftp.authTls = true;

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

  // Change to the remote directory where the files are located.
  // This step is only necessary if the files are not in the root directory
  // of the FTP account.
  try {
    ftp.changeRemoteDir('qa');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Download all files with filenames matching "*.txt";
  // The files are downloaded into c:/temp/qa_output
  final numFilesDownloaded = ftp.mGetFiles('*.txt', 'c:/temp/qa_output');
  if (numFilesDownloaded < 0) {
    print(ftp.lastErrorText);
    return;
  }

  ftp.disconnect();

  print('$numFilesDownloaded Files Downloaded!');
}