Dart
Dart
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.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 = 'ftp.example.com';
ftp.username = 'myLogin';
ftp.password = 'myPassword';
// Use explicit TLS
ftp.authTls = true;
ftp.port = 21;
// Connect and login to the FTP server.
try {
ftp.connect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Iterate over .txt files.
ftp.listPattern = '*.txt';
final n = ftp.getDirCount();
print('n = $n');
var i = 0;
while (i < n) {
print('$i: ${ftp.getFilename(i)}');
i++;
}
}