Sample code for 30+ languages & platforms
Dart

Remove Directory

See more FTP Examples

Delete a remote FTP directory.

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 = 'login';
  ftp.password = 'password';

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

  // Delete a directory on the FTP server.  The directory
  // must not contain any files, otherwise an error status
  // will be returned.  Most FTP servers do not allow
  // directories containing files to be deleted.
  try {
    ftp.removeRemoteDir('newDirName');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  ftp.disconnect();
}