How to upload and share file automatically

Nextcloud version 12
Operating system and version Centos 7.3
Apache 2.4.6
PHP version 70

I would like to know can Nextcloud upload and share file automatically?

I saw from the Doc that it can be done by calling Webdav API with curl. I’m not sure if there are any further configuration that I have to do or I can just call the API directly.

I tried to run this command:
curl -u admin:pass -T testfile.txt “https://mynextcloud.co.th/remote.php/dav/files/testfile.txt

and then there is an error below:
<d:error xmlns:d=“DAV:” xmlns:s=“http://sabredav.org/ns”>
<s:exception>Sabre\DAV\Exception\Forbidden</s:exception>
<s:message>Permission denied to create file (filename testfile.txt)</s:message>
</d:error>

here is a nextcloud log:
{“reqId”:“WYk0H4IiMH8GiSK26jkHggAAAAI”,“level”:1,“time”:“2017-08-08T03:46:39+00:00”,“remoteAddr”:“xxx.xxx.xxx.xxx”,“user”:"–",“app”:“admin_audit”,“method”:“PUT”,“url”:"/remote.php/dav/files/testfile.txt",“message”:“Login attempt: “admin””,“userAgent”:“curl/7.29.0”,“version”:“12.0.0.29”}
{“reqId”:“WYk0H4IiMH8GiSK26jkHggAAAAI”,“level”:1,“time”:“2017-08-08T03:46:39+00:00”,“remoteAddr”:“xxx.xxx.xxx.xxx”,“user”:“5AF09698-865E-420F-9E33-91215EAF4058”,“app”:“admin_audit”,“method”:“PUT”,“url”:"/remote.php/dav/files/testfile.txt",“message”:“Login successful: “5AF09698-865E-420F-9E33-91215EAF4058"”,“userAgent”:“curl/7.29.0”,“version”:“12.0.0.29”}
{“reqId”:“WYk0H4IiMH8GiSK26jkHggAAAAI”,“level”:3,“time”:“2017-08-08T03:46:39+00:00”,“remoteAddr”:“10.151.19.70”,“user”:“5AF09698-865E-420F-9E33-91215EAF4058”,“app”:“PHP”,“method”:“PUT”,“url”:”/remote.php/dav/files/testfile.txt",“message”:“call_user_func() expects parameter 1 to be a valid callback, class ‘OCA\QuotaWarning\AppInfo\Application’ does not have a method ‘login’ at /var/www/html/nextcloud/lib/private/legacy/hook.php#106”,“userAgent”:“curl/7.29.0”,“version”:“12.0.0.29”}

Is my command correct ?
what is wrong for this case ?

The username in the url seems to be missing:
https://docs.nextcloud.com/server/10/user_manual/files/access_webdav.html#accessing-files-using-curl

Hi tflidd

Thank you for you reply. I followed the Doc you provided. I just added the User ID to the URL and then it’s work but the Doc doesn’t show up how to share a file with curl.

Do you have any suggestion ?

There is also an API in the docs for that:
https://docs.nextcloud.com/server/12/developer_manual/core/ocs-share-api.html#create-a-new-share

you can do it with curl as well. However, there is a python client that can do all of that and it’s even in the examples: