Using curl/wget to download file from password protect link

I am using nextcloud 18 and I would like to know if there is a way to download a shared file from a link that it is password protected using curl or wget.
I have a shared file protected by password on this url:

When accessing that link on the browser, I am presented with this screen:

And after typing the password, the download begins.
I need to automate that process to download using command line tools like curl or wget, but I have not found a way to do it.

Note that there is no USERNAME involved in the process, just a password. So using , for example,
curl -u user:password
wont work.

This works:

curl -u “shareid:password” -H ‘X-Requested-With: XMLHttpRequest’ ‘

share id is the string after the s/ and before the /download

Hi, it seems to work when the protected public link is done for a file, but not for a folder.
I get the following message in the latter case : This is the WebDAV interface. It can only be accessed by WebDAV clients such as the Nextcloud desktop sync client.

d you have the same behaviour?


1 Like

Yes, I have the same behaviour.
How can I download a specific file from a shared folder using a UNIX terminal?

Hopefully you can change the link:


I think the path is relative. You can also use in the same folder it without “path”:


It doesn’t work for me. I have a password protected shared directory and I want to be able to download only one file from it using a simple command in a console. I know about davfs2, but it’s too complicated for my scenario, I’m wondering, maybe there is a simpler solution, like
curl -u "shareID:passWD" -H "X-Requested-With: XMLHttpRequest" "" --output

Yes. But I think you must not use “public.php/webdav” but “s” in the path. See then i think there is a problem with the password because the uses cookies …

Yay! I finally found a solution for my and @gsalin problem!
It’s really simple and doesn’t require any additional installations, like davfs2.

If you have password protected shared directory, and you need to download only one file from it, you just need to place the specific file name in the url after “…public.php/webdav/”. So the resulting bash command will be like this:
curl -u "shareID:passWD" -H "X-Requested-With: XMLHttpRequest" "" -o


First thank you for your code. I was able to download a single file from a shared directory. However I am unable to download a single shared file in a non-shared directory. Any direction on how to do this?

I used Rclone. have a look at this 11.04 - How do I recursively copy/download a whole webdav directory? - Ask Ubuntu @chrish is a lifesaver! If youre trying to download something from nextcloud. Setup a config as @crish said using rclone config. the URL is and username would be the string after the s/.

You also require a password if the storage is password protected. Then just copy as he says in the answer.