handleRename method

void handleRename(
  1. String argument,
  2. FtpSession session
)

Implementation

void handleRename(String argument, FtpSession session) {
  if (session.serverType == ServerType.readOnly) {
    session.sendResponse('550 Command not allowed in read-only mode');
    return;
  }

  if (argument.isEmpty) {
    session.sendResponse('501 Syntax error in parameters or arguments');
    return;
  }

  // Parse the rename command arguments (oldname newname)
  final parts = argument.split(' ');
  if (parts.length != 2) {
    session.sendResponse('501 Syntax error in parameters or arguments');
    return;
  }

  final oldName = parts[0];
  final newName = parts[1];

  // Check if the file/directory exists
  if (!session.fileOperations.exists(oldName)) {
    session.sendResponse('550 File not found');
    return;
  }

  try {
    // Perform the rename operation directly
    session.renameFileOrDirectory(oldName, newName);
  } catch (e) {
    // Error handling is done in the session method
  }
}