enterActiveMode method

Future<void> enterActiveMode(
  1. String parameters
)

Implementation

Future<void> enterActiveMode(String parameters) async {
  try {
    List<String> parts = parameters.split(',');
    if (parts.length < 6) {
      sendResponse('501 Syntax error in PORT parameters');
      return;
    }
    // Validate all 6 parts are valid byte values (0-255)
    final values = <int>[];
    for (final part in parts.take(6)) {
      final v = int.tryParse(part.trim());
      if (v == null || v < 0 || v > 255) {
        sendResponse('501 Syntax error in PORT parameters');
        return;
      }
      values.add(v);
    }
    String ip = values.take(4).join('.');
    int port = values[4] * 256 + values[5];

    // Plain TCP connect. With PROT P the server still acts as the TLS
    // *server* on this connection (RFC 4217 ยง7: the FTP client is always
    // the TLS client); the handshake happens in openDataConnection().
    dataSocket = await Socket.connect(ip, port);
    sendResponse('200 Active mode connection established');
  } catch (e) {
    sendResponse('425 Can\'t enter active mode');
    logger.generalLog('Error entering active mode: $e');
  }
}