3

I am running a nextcloud instance and I am trying to download a directory with an API call using the library requests.

I can download a zip file using an API call. Now what I would like to to is to have an unzipped directory on my nextcloud instance and download it via an API call. It doesn't matter to me if I get a zip file back when I do the API call, I just want to have it unzipped in the cloud.

For instance, I can put an unzipped directory there and when I download it in my browser, nextcloud gives me back a zip file. This behaviour I want in an API call.

Now if I put a zipped file on there I can download the file like so:

import os
import requests


response = requests.request(
        method="get",
        url=f"https://mycloud/remote.php/dav/files/setup_user/{name_dir}/",
        auth=("my_user", my_token),
    )

    if response.status_code == 200:
        with open("/path/to/my/dir/file_name.zip"), "wb") as file:
            file.write(response.content)

That writes me my zipfile which is in the cloud to a local file_name.zip file. My problem is now that if I have an unzipped directory in the cloud it doesn't work. Doesn't work meaning that I get a file back which has the content:

This is the WebDAV interface. It can only be accessed by WebDAV clients such as the Nextcloud desktop sync client.

I also tried to do this with wget wget --recursive --no-parent https://path/to/my/dir and I got the same file with the same content back.

So I assume that the WebDav API of nextcloud doesn't allow me to do it in the way I want to do it. Not I am wondering what I am doing wrong or if what I want is doable. Also I don't get why in the browser this works fine. I just select the unzipped folder and can download it with a click. In the nextcoud community it has been suggested to use Rclone (https://help.nextcloud.com/t/download-complete-directory-from-nextcloud-instance/77828), but I would prefer to not use a dependency that I have to set up on every machine where I want to run this code.

Any help is very much appreciated! Thanks a bunch in advance!

PS: In case anyone wonders why I would want to do this: It's way more convenient when I would like to change just a single file in my dir in the cloud. Otherwise I have to unzip, change file, zip and upload again.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Micromegas
  • 1,499
  • 2
  • 20
  • 49

0 Answers0