reinitialize method

void reinitialize()

Reinitialize the session to its initial state (RFC 959 REIN). Resets authentication, transfer parameters, data connections, and working directory. If a transfer is in progress, data connections are left open until the transfer completes naturally.

Implementation

void reinitialize() {
  isAuthenticated = false;
  cachedUsername = null;
  pendingRenameFrom = null;
  epsvAllMode = false;

  // Reset TLS negotiation state (but NOT tlsActive, securityContext,
  // securityMode, requireEncryptedData — those are connection-level).
  pbszReceived = false;
  protectionLevel = ProtectionLevel.clear;

  // Reset working directory to root
  fileOperations.currentDirectory = fileOperations.rootDirectory;

  if (!transferInProgress) {
    // Only close data connections if no transfer is active.
    // RFC 959: "allow any transfer in progress to be completed"
    try {
      dataSocket?.close();
    } catch (_) {}
    try {
      dataListener?.close();
    } catch (_) {}
    try {
      _secureDataListener?.close();
    } catch (_) {}
    dataSocket = null;
    dataListener = null;
    _secureDataListener = null;
    _gettingDataSocket = null;
  }
  // If a transfer IS in progress, data connections remain open.
  // They will be cleaned up when the transfer completes.
}