cURL PUT Issue While Attempting to Upload File

Hello,

I get the following error when attempting to use cURL client on command line to upload a file to NextCloud.

** **<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">** ** <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>** ** <s:message>No public access to this resource., Username or password was incorrect, No 'Authorization: Bearer' header found. Either the client didn't send one,or the server is mis-configured, Username or password was incorrect</s:message>** **</d:error>** **

While I have read other archived posts in the NextCloud forums regarding similar issues, it is unclear what solutions were found if any.

My command line call is as follows:

C:\somedata\> curl -X PUT --data-binary .\myfile.txt -u "user@mydomain.net:mypass1234wrd" "http://mynextcloudserver/nextcloud/remote.php/dav/files/user/purchase_orders/123path/myfile.txt"

NOTES:
The nextcloud instance is using LDAP for user logins.
The user ID and password work fine when logging into the nextcloud front end.

Thanks for any enlightenment.

Do you use second factor authentication?

In such a case, the best is to create an app-password for this purpose and use this app-password for logins.

I think you have to escape the @ in your username.

No 2FA. This is an internal office system that is used for internal office files.

I have tried it both ways. Still no joy.

Always the

error?

Did you try the app password. Perhaps the bearer is always needed for normal username/pw combination …

I saw the ‘No Authorization Bearer’ message.

Maybe someone from dev could tell us what this obscure message actually means.

Tried app password method. Still not working. Same error message.

The message is telling you that the resource is not public, then username or password were not correct and that the server also tried to process a authorization token, but there was none.

Apparently, our code has issues when the username contains an @ character.

The following worked on my dev instance:

I used p@willis.net as username.

curl -X PUT --location "https://server.internal/remote.php/dav/files/p@willis.net/hello2.txt" \
    -H "Authorization: Basic cEB3aWxsaXMubmV0OnRlc3QxMjM0NTY=" \
    -H "Content-Type: text/plain; charset="utf-8"" \
    -H "Cookie: XDEBUG_SESSION=PHPSTORM" \
    -d 'Hello World!'

cEB3aWxsaXMubmV0OnRlc3QxMjM0NTY= is the base64 encoded version of p@willis.net:test123456

I have now tried this method. I get the same error.
Perhaps there is a server misconfiguration as it says.

I know the user id and pass work fine when logging into the web interface.
The web front end works fine for users.

What server config settings could be relevant?

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>
  <s:message>No public access to this resource., Username or password was incorrect, No 'Authorization: Bearer' header found. Either the client didn't send one,
 or the server is mis-configured, Username or password was incorrect</s:message>
</d:error>