rename method

  1. @override
Future<FtpFile> rename(
  1. String newName
)
override

Implementation

@override
Future<FtpFile> rename(String newName) async {
  if (newName.contains('/')) {
    throw FtpException('New name cannot contain path separator');
  }
  final newFile = parent.getChildFile(newName);
  if (newFile.path == path) {
    return this;
  }
  if (!await newFile.parent.exists()) {
    throw FtpException('Parent directory of new file does not exist');
  }
  final response = await FtpCommand.RNFR.writeAndRead(_client.socket, [path]);
  if (!response.isSuccessful) {
    throw FtpException('Cannot rename file');
  }
  final response2 =
      await FtpCommand.RNTO.writeAndRead(_client.socket, [newFile.path]);
  if (!response2.isSuccessful) {
    throw FtpException('Cannot rename file');
  }
  return newFile;
}