retrieveFile method
Implementation
Future<void> retrieveFile(String filename) async {
if (!openDataConnection()) {
return;
}
try {
String fullPath = _getFullPath(filename);
if (!_isPathAllowed(fullPath)) {
sendResponse('550 Access denied');
return;
}
File file = File(fullPath);
if (await file.exists()) {
Stream<List<int>> fileStream = file.openRead();
await fileStream.pipe(dataSocket!);
dataSocket!.close();
dataSocket = null;
sendResponse('226 Transfer complete');
} else {
sendResponse('550 File not found');
}
} catch (e) {
sendResponse('550 File transfer failed');
dataSocket = null;
}
}