Occ transfering ownership can't find path

Nextcloud version (eg, 12.0.2): 14.0.3
Operating system and version (eg, Ubuntu 17.04): CENTOS 7.5 kvm
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4
PHP version (eg, 7.1): 7.0

The issue you are facing: I’m trying to transfer ownership of a specific directory from one user (user1) to another user (user2) but files:transfer-ownership script fails. It says it can’t find the path I provide. I’ve tried all kinds of paths to the directory but none ever work. The user I’m running php as is the owner of /nextclouddata and all the files. I even tried absolute path and it still doesn’t work.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:
Try out files:scan, you can see the path exists and scripts work:

synyc@ds1055 [~/cloud.synyc.org]# php occ files:scan --path="user1/files/MyTempShare"
Starting scan for user 1 out of 1 (user1)

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 2       | 5     | 00:00:02     |
+---------+-------+--------------+

Now Try files:transfer-ownership with path:

synyc@ds1055 [~/cloud.synyc.org]# php occ files:transfer-ownership --path=“/user1/files/MyTempShare” user1 user2
Unknown path provided: “/user1/files/MyTempShare”

or

synyc@ds1055 [~/cloud.synyc.org]# php occ files:transfer-ownership --path=“/home/synyc/nextclouddata/user1/files/MyTempShare” user1 user2
Unknown path provided: “/home/synyc/nextclouddata/user1/files/MyTempShare”

Here’s the directory:

synyc@ds1055 [~/cloud.synyc.org]# ls -ltr /home/synyc/nextclouddata/user1/files/MyTempShare
total 42384
-rw-r--r-- 1 synyc synyc  1817094 Sep 28 19:59 IMG_2427.JPG
-rw-r--r-- 1 synyc synyc  2512754 Sep 30 19:58 DanceDJY-Ad-1-4-2016.pdf
-rw-r--r-- 1 synyc synyc 39067012 Oct  5 19:37 RPL8ftStraight-SY19_Folder.zip
drwxr-xr-x 2 synyc synyc       68 Oct 18 03:25 Taco

Just FYI, the --help for the command … seems like it should work to transfer ownership of just 1 dir vs everything:

synyc@ds1055 [~/cloud.synyc.org]# php occ files:transfer-ownership --help
Usage:
  files:transfer-ownership [options] [--] <source-user> <destination-user>

Arguments:
  source-user           owner of files which shall be moved
  destination-user      user who will be the new owner of the files

Options:
      --path=PATH       selectively provide the path to transfer. For example --path="folder_name" [default: ""]
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --no-warnings     Skip global warnings, show command output only
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  All files and folders are moved to another user - shares are moved as well.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' =>
  array (
    0 => 'cloud.synyc.org',
  ),
  'datadirectory' => '/home/synyc/nextclouddata',
  'overwrite.cli.url' => 'https://cloud.synyc.org/',
  'htaccess.RewriteBase' => '/',
  'htaccess.IgnoreFrontController' => true,
  'dbtype' => 'mysql',
  'version' => '14.0.3.0',
  'dbname' => 'xxxx',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'xxx',
  'dbpassword' => 'xxxx',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'mail_from_address' => 'nc-noreply',
  'mail_smtpauth' => 1,
  'mail_domain' => 'synyc.org',
  'mail_smtpport' => '465',
  'mail_smtpname' => 'nc-noreply@synyc.org',
  'mail_smtppassword' => 'xxxxx',
  'mail_smtpsecure' => 'ssl',
  'mail_smtphost' => 'mail.synyc.org',
  'updater.secret' => 'xxxx',
);

Use relative paths, not absolute ones, that is what I have seen. It will automatically look in the user you are transferring from for the path. So start with “files/blah/blah” rather than “user1/files”

Thanks, but still doesn’t work:

synyc@ds1055 [~/cloud.synyc.org]# php occ files:transfer-ownership --path=“files/MyTempShare” user1 user2
Unknown path provided: “files/MyTempShare”

Seems there is a bug in the script: apps/files/lib/Command/TransferOwnership.php
I added an extra line to output $this->sourcePath…

if (!$view->is_dir($this->sourcePath)) {
                        $output->writeln("<error>Unknown path provided: $sourcePathOption</error>");
                        $output->writeln("<error>sourcePath: $this->sourcePath</error>");
                        return 1;
                }

the results

synyc@ds1055 [~/cloud.synyc.org]# php occ files:transfer-ownership  --path=“MyTempShare” user1 user2
Unknown path provided: “MyTempShare”
sourcePath: user1/files/“MyTempShare”

oops! gotta get rid of those quotes, right? This actually works:

php occ files:transfer-ownership --path=MyTempShare user1 admin
Analysing files of user1 ...
    5 [============================] < 1 sec 10.0 MiB

But obviously a bad solution because some of the other folders I want to transfer have spaces in them.

Is there a way to report this bug?

Not a bug. To get rid of the spaces use ‘’. It uses the same copy mechanism as native Linux does.

Ah! OK. Single quotes work. Thanks!
Still might be good to update the help for that script here:
https://docs.nextcloud.com/server/14/admin_manual/configuration_server/occ_command.html?highlight=index%20php#file-operations

Right now it just says this about transferring ownership:

You may transfer all files and shares from one user to another. This is useful before removing a user:

Would be nice if it mentioned you can use the --path option, but it works differently from the scan command (which is right above it in the docs), since you shouldn’t put the user id or the word “files” in the path. Then give one working example, it will save people a lot of time :smile: