NextCloud: Transfer Ownership
Tags: nextcloud, owncloud, transfer, ownership
Published: 2019-06-18 05:04:50

---
title: NextCloud: Transfer Ownership
published: true
description: NextCloud is an open-source self-hosted file share platform forked from ownCloud. This post shows how to transfer ownership. A simple way is to download all and then upload them by the new owner. But it is impractical when they are so big. Alternatively, command lines with occ are available.
tags: nextcloud, owncloud, transfer, ownership
cover_image: https://thepracticaldev.s3.amazonaws.com/i/uiu1iol83dn1kkr80qud.png
---

*\* The cover image is [officially released](https://nextcloud.com/press/).*

## Summary

[NextCloud](https://nextcloud.com/) is an open-source self-hosted file share platform forked from [ownCloud](https://owncloud.org/).

I had to transfer the ownership of shared files/directories due to personnel change the other day.

A simple way was to download all the files and then upload them by the new owner.
But it was too impractical as they were so big.

Alternatively, I carried it out via command lines with [`occ`](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html).
`occ` is NextCloud's command-line interface to perform server operations whose name is after ["o"wn"C"loud (the origin) "C"onsole](https://doc.owncloud.com/server/admin_manual/configuration/server/occ_command.html).

## Environment

- OS: [CentOS](https://www.centos.org/) 6
- Web: [Apache](https://www.apache.org/)'s [httpd](https://httpd.apache.org/) 2
- APP: [PHP](https://www.php.net/) 7.3
- File Share Platform: NextCloud 16

## Tutorial

The command of `occ` to use is [`Files`](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#file-operations)' [`transfer-ownership`](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#file-operations)
The basic format is:

```console
$ occ files:transfer-ownership <from-user> <to-user>
```

In my environment, `occ` didn't exist among [`PATH`](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable.
Therefore, I used [`find`](https://en.wikipedia.org/wiki/Find_(Unix)) to get the path, and specify it in the command line as `<lib-dir-path>/occ`.
Additionally, I had to run it with specified PHP.

```console
$ php73 <lib-dir-path>/occ files:transfer-ownership <from-user> <to-user>
```

Finally, it was required to run as the web user, `apache` in my case:

```console
$ sudo -u apache php73 <lib-dir-path>/occ files:transfer-ownership <from-user> <to-user>
```

The output was:

```console
Analysing files of <from-user> ...
 16442 [============================]
Collecting all share information for files and folder of <from-user> ...
   25 [============================]
Transferring files to <to-user>/files/transferred from <from-user> on 2019-06-12 01-56-02 ...
Restoring shares ...
Share with id 4 points at deleted file, skipping
  1/25 [=>--------------------------]   4%Share with id 11 points at deleted file, skipping
  2/25 [==>-------------------------]   8%Share with id 12 points at deleted file, skipping
  3/25 [===>------------------------]  12%Share with id 16 points at deleted file, skipping
  7/25 [=======>--------------------]  28%Share with id 1 points at deleted file, skipping
  8/25 [========>-------------------]  32%Share with id 9 points at deleted file, skipping
 13/25 [==============>-------------]  52%Share with id 90 points at deleted file, skipping
 14/25 [===============>------------]  56%Share with id 91 points at deleted file, skipping
 15/25 [================>-----------]  60%Share with id 28 points at deleted file, skipping
 19/25 [=====================>------]  76%Share with id 57 points at deleted file, skipping
 20/25 [======================>-----]  80%Share with id 58 points at deleted file, skipping
 21/25 [=======================>----]  84%Share with id 60 points at deleted file, skipping
 22/25 [========================>---]  88%Share with id 61 points at deleted file, skipping
 23/25 [=========================>--]  92%Share with id 87 points at deleted file, skipping
 24/25 [==========================>-]  96%Share with id 88 points at deleted file, skipping
 25/25 [============================] 100%
```

As a result, **a new directory named "transferred from \<from-user\> on 2019-06-12 01-56-02" (printed in the console) was created in \<to-user\>'s home** and all the files were owned by the new owner there.
All I had to do then was to log in as \<to-user\> and move them as needed : )

---

## References

- NextCloud's ["Transferring files to another user"](https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/file_sharing_configuration.html#transferring-files-to-another-user)
- Other commands
    - `occ list` lists commands.
    - `occ help <command>` displays help for the command.    
        For example, `occ help files` will show subcommands: [`cleanup`](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#cleanup), [`scan`](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#scan), and `transfer-ownership`.

<center>🌱 🦉 🌿 🦔 🌳</center>

Thank you for your reading.
Happy serving.