Download complete directory from nextcloud instance

I was wondering if there is a convenient way to download a full directory with an API call from a nextcloud server. Right now I can get a zip file by doing this with python’s request library:

response = requests.request(
        method="get",
        url=f"https://mynextcloud.de/remote.php/dav/files/{user}/{project_name}/"
        f"{name_file}",
        auth=(user, token),
    )
    print(response.status_code)
    return response

If I get a 200 response I can save the zip file to a local directory. But what would be way more convenient is to not have a zip file but to put a folder with its subfolders and contents on the cloud and to download it with a single API call.

Is that possible with the WebDav API somehow and if so, how could I do this? I know there is this library https://github.com/owncloud/pyocclient but it doesn’t say anything about downloading complete dirs. Using wget like this wget wget --recursive https://cloud.heatbeat.de/remote.php/dav/files/setup_user/test/ --http-user=xxx --http-password=xxx. downloads an index file saying This is the WebDAV interface. It can only be accessed by WebDAV clients such as the Nextcloud desktop sync client.. So I guess wget and WebDav don’t work well together.

Thanks very much for the help! Appreciated!

Personally, I’d recommend using Rclone to do it.

Once you have it installed and configured, it should be as easy as rclone copy CLOUD: ./.

Disclaimer: I am a contributor to both Rclone and Nextcloud.

1 Like

Thank you very much @gary-kim . I will look into Rclone but I’d prefer a way without bringing in another dependency if this is possible. Especially that code needs to run on various machines. Thus the setup costs would be high to configure everything on many different machines. Is there another way that you know of?