Trouble downloading SQLite files with FTPConnect in Flutter: Larger files incomplete

I’m encountering an issue with downloading SQLite database files using the FTPConnect library in Flutter. Specifically, when I attempt to download larger SQLite files (e.g., 4MB or 15MB), the downloaded files are incomplete and cannot be opened. However, smaller files of the same type download and open without any issues.

Here’s a summary of the problem:

  • Library Used: FTPConnect in Flutter for FTP operations.
  • Issue: Larger SQLite files are incompletely downloaded as bytes, making them unreadable.
  • Observations: Smaller SQLite files download and open correctly, indicating that the issue is specific to larger file sizes.
  • Attempts: I’ve tried setting the transfer type to binary (ftpConnect.setTransferType(TransferType.binary)) and handling download retries (ftpConnect.downloadFileWithRetry). Despite these efforts, larger files still download incompletely.

What could be causing this issue with FTPConnect where larger SQLite files are incompletely downloaded as bytes? How can I ensure that larger SQLite files are downloaded completely and correctly?

Code Snipped:

// Relevant code snippet used for downloading SQLite files
// Example of downloading a file with FTPConnect

Future<void> _deleteAndDownloadFile(context) async {
  showDialog(
      context: context,
      builder: (context) => const Center(child: CircularProgressIndicator()));

  var settingsProvider = Provider.of<SettingsProvider>(context, listen: false);
  var databaseProvider = Provider.of<DatabaseProvider>(context, listen: false);

  final FTPConnect ftpConnect = FTPConnect(settingsProvider.settings.ftpUrl,
      user: settingsProvider.settings.ftpUsername,
      pass: settingsProvider.settings.ftpPassword);

  try {
    // Connect to FTP server and set transfer type
    await ftpConnect.connect();
    await ftpConnect.setTransferType(TransferType.binary);
    await ftpConnect.sendCustomCommand('TYPE I');

    // Directory setup and file handling
    Directory appDocDirectory = await getApplicationDocumentsDirectory();
    Directory directory = Directory('${appDocDirectory.path}/files');

    if (!(await directory.exists())) {
      await directory.create(recursive: true);
    }

    // Delete existing file if present
    final File file = File('${directory.path}/${settingsProvider.getSavedSahaElemanNo()}.db');
    if (await file.exists()) {
      await file.delete();
    }

    // Attempt to download the SQLite file
    await ftpConnect.downloadFileWithRetry(
      '/DbFieldTeam/${settingsProvider.getSavedSahaElemanNo()}.db', file,
      pRetryCount: 2,
      onProgress: (progressInPercent, totalReceived, fileSize) =>
          print('Progress: $progressInPercent, Total Received: $totalReceived, File Size: $fileSize'));

    final int fileSize = await file.length();
    print('File size: $fileSize bytes');

    // Further database operations and error handling
    // (Open database, fetch data, update UI, etc.)

  } catch (e) {
    // Error handling for various exceptions
    print(e);
    switch (e.runtimeType) {
      case FTPConnectException:
        // Handle FTP connection issues
        break;
      case DatabaseException:
        // Handle SQLite database errors
        break;
      case SocketException:
        // Handle network connectivity issues
        break;
      default:
        // Handle other errors
        break;
    }
  } finally {
    // Close dialogs, cleanup, and navigation
    Navigator.pop(context);
  }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật