handleRename method

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

Implementation

Future<void> handleRename(String argument, FtpSession session) async {
  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;
  }
  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];
  if (!session.fileOperations.exists(oldName)) {
    session.sendResponse('550 File not found');
    return;
  }
  await session.renameFileOrDirectory(oldName, newName);
}