Good day. I want to give a user or a group of users access to a file or folder. How to do it with cURL?
I think you can create a public share to a file and then use
curl -X GET "https://nextcloud.example.com/index.php/s/SHARE_ID/download"
Will it be public access for everyone? I only need access for individual users.
Yes you can also use cURL with user. Read here.
curl -u user:pass -o file.ext "https://nextcloud.example.com/remote.php/dav/files/username/path/to/file.ext"
You must use the WebDAV url of the user.
Hi @Tima,
You should use curl as a WebDAV Client.
Let’s say you are user Jack with the user ID jack
, and you have a file named Readme.pdf located in the root of your cloud. You can access that file using curl
like this:
curl -u jack:${jacks_app_password} --output Readme.pdf https://cloud.domain.tld/remote.php/dav/files/jack/Readme.pdf
You can add your credentials to the file ~/.netrc, which allows you to access it without providing a username and password in cleartext in the comandline every time:
curl --netrc --output Readme.pdf https://cloud.domain.tld/remote.php/dav/files/jack/Readme.pdf
For the recipient of your share, Jill, with the user ID jill
, it’s the same process. However, Jill needs to know where the shared file is located in her file tree. It will appear at the location where Jill defined it. The default location is /, but this can be changed by the user. This setting is configured under the “Sharing” tab in the user settings. You won’t be able to know her exact setting. e.g,:
if Jill has the shared Readme.pdf located in /Shares/Readme.pdf
instead of the root (/
), she would download it with the following command:
curl -u jill:${jills_app_password} --output Readme.pdf https://cloud.domain.tld/remote.php/dav/files/jill/Shares/Readme.pdf
Or in case she uses her ~/.netrc file:
curl --netrc --output Readme.pdf https://cloud.domain.tld/remote.php/dav/files/jill/Shares/Readme.pdf
Hope this helps to understand.
Much and good luck,
ernolf
Thanks, I’ll try that.