move method

  1. @override
Future<FtpFile> move(
  1. String newPath
)
override

Implementation

@override
Future<FtpFile> move(String newPath) async {
  final newFile = newPath.startsWith(_client.fs.rootDirectory.path)
      ? FtpFile(path: newPath, client: _client)
      : parent.getChildFile(newPath);
  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 move file');
  }
  final response2 =
      await FtpCommand.RNTO.writeAndRead(_client.socket, [newFile.path]);
  if (!response2.isSuccessful) {
    throw FtpException('Cannot move file');
  }
  return newFile;
}