Dart
Dart
Delete Files Matching Pattern
See more FTP Examples
The DeleteMatching method deletes all files in the current remote directory matching a wildcarded filename.Chilkat Dart Downloads
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 = 'www.chilkatsoft.com';
ftp.username = 'MyLogin';
ftp.password = 'MyPassword';
// 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 to be deleted are located.
// for the FTP account.
try {
ftp.changeRemoteDir('junk');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Delete all files with filenames matching "ftp_*.asp"
final numDeleted = ftp.deleteMatching('ftp_*.asp');
if (numDeleted < 0) {
print(ftp.lastErrorText);
return;
}
ftp.disconnect();
print('$numDeleted Files Deleted!');
}