Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webdav public access (link shares) #12

Open
PVince81 opened this issue Jul 14, 2014 · 7 comments
Open

Webdav public access (link shares) #12

PVince81 opened this issue Jul 14, 2014 · 7 comments

Comments

@PVince81
Copy link
Contributor

OC 7 provides a new webdav interface for public links, mainly used by server to server sharing.
Would be good to be able to open such links with the API as well.

It's probably just a matter of passing the share token as uid and the password as password (if any) as basic auth arguments.

@PVince81 PVince81 changed the title Webdav public access Webdav public access (link shares) Jun 19, 2017
@yarikoptic
Copy link

FWIW, would be very interested to see solution here as well ;)

@PVince81
Copy link
Contributor Author

PVince81 commented Sep 7, 2017

Possible implementation: when constructing the client class, pass an extra optional arg that tells "public=True". When that value is set, switch the Webdav endpoint to "public.php/webdav".
Then all the caller needs to do is to call login() and pass the share token as user id and the link password (if any) as password.

That would be the minimal implementation.

To make it more user friendly, maybe the Client could have a static method from_link(public_link) that parses the token from the link and does all of the above and returns an initialized client.

Pull requests welcome ;-)

@mrwunderbar666
Copy link
Contributor

mrwunderbar666 commented Apr 10, 2020

I added a new method anon_login(), because the default login() method would make an API call that requires an account.

My first time doing something like this and I hope the PR is ok ¯_(ツ)_/¯

Please note that for using the put_file() method, it is required to pass an empty string as remote location: put_file("", local_file). Solution would be to add a drop_file() method that automatically uses the root folder as remote destination

@PVince81
Copy link
Contributor Author

@mrwunderbar666 thanks a lot, please check the PR review :-)

@mrwunderbar666
Copy link
Contributor

I think this can be closed now, was fun helping out a bit.
There are still some limitations: e.g. downloading a directory as ZIP would require a different API url.

Also please add this to the readme (I forgot to push it)


Example for uploading a file to a public shared folder:

.. code-block:: python

    import owncloud

    public_link = 'http://domain.tld/owncloud/A1B2C3D4'

    oc = owncloud.Client.from_public_link(public_link)
    oc.drop_file('myfile.zip')


Example for downloading a file from a public shared folder with password:

.. code-block:: python

    import owncloud

    public_link = 'http://domain.tld/owncloud/A1B2C3D4'
    folder_password = 'secret'

    oc = owncloud.Client.from_public_link(public_link, password=folder_password)
    oc.get_file('/sharedfile.zip', 'download/destination/sharedfile.zip')

@gthieleb
Copy link

The provided documentation snippet does not work for me.
I have to explicitly call anon_login with token, password.

Without anon_login:

url = os.environ.get("PUBLIC_SHARE_URL")
password = os.environ.get("PUBLIC_SHARE_PASSWORD")
oc = owncloud.Client.from_public_link(url, password=password, debug=True)

Output:

oc.list("/")
DAV request: PROPFIND /
Headers:  {'Depth': '1'}
DAV status: 401
---------------------------------------------------------------------------
HTTPResponseError                         Traceback (most recent call last)
<ipython-input-1-27789b406e48> in <module>
----> 1 oc.list("/")

~/python/djnextcloud_project/pyocclient/owncloud/owncloud.py in list(self, path, depth, properties)
    467             data = None
    468 
--> 469         res = self._make_dav_request('PROPFIND', path, headers=headers, data=data)
    470         # first one is always the root, remove it from listing
    471         if res:

~/python/djnextcloud_project/pyocclient/owncloud/owncloud.py in _make_dav_request(self, method, path, **kwargs)
   1813         if res.status_code in [204, 201]:
   1814             return True
-> 1815         raise HTTPResponseError(res)
   1816 
   1817     def _parse_dav_response(self, res):

HTTPResponseError: HTTP error: 401

With anon_login:

oc = owncloud.Client.from_public_link(url, debug=True)
oc.anon_login(folder_token=url.split('/')[-1], folder_password=password)

Output:

oc.list("/")
DAV request: PROPFIND /
Headers:  {'Depth': '1'}
DAV status: 207
Out[1]: 
[File(path=/April/,file_type=dir,attributes={'{DAV:}getlastmodified': 'Mon, 04 May 2020 09:19:39 GMT', '{DAV:}resourcetype': None, '{DAV:}quota-used-bytes': '13922874319', '{DAV:}quota-available-bytes': '5779637286', '{DAV:}getetag': '"5eafde2be441f"'}),
 File(path=/Lied über Schiffe.mp4,file_type=file,attributes={'{DAV:}getlastmodified': 'Wed, 29 Apr 2020 19:13:29 GMT', '{DAV:}getcontentlength': '44728255', '{DAV:}resourcetype': None, '{DAV:}getetag': '"b8f437515d152d330168e9100797da2a"', '{DAV:}getcontenttype': 'video/mp4'}),
 File(path=/Mai/,file_type=dir,attributes={'{DAV:}getlastmodified': 'Sun, 03 May 2020 20:09:05 GMT', '{DAV:}resourcetype': None, '{DAV:}quota-used-bytes': '1744933305', '{DAV:}quota-available-bytes': '5779637286', '{DAV:}getetag': '"5eaf24e20eea0"'}),
 File(path=/März/,file_type=dir,attributes={'{DAV:}getlastmodified': 'Fri, 03 Apr 2020 15:39:30 GMT', '{DAV:}resourcetype': None, '{DAV:}quota-used-bytes': '4032809994', '{DAV:}quota-available-bytes': '5779637286', '{DAV:}getetag': '"5e8758b2b57f8"'}),
 File(path=/Tinto Rap (1).m4a,file_type=file,attributes={'{DAV:}getlastmodified': 'Wed, 15 Apr 2020 20:34:22 GMT', '{DAV:}getcontentlength': '1749165', '{DAV:}resourcetype': None, '{DAV:}getetag': '"119059981562e41fb4cc75dce97f3176"', '{DAV:}getcontenttype': 'audio/mp4'}),
 File(path=/test.txt,file_type=file,attributes={'{DAV:}getlastmodified': 'Sat, 14 Nov 2020 16:00:07 GMT', '{DAV:}getcontentlength': '1024', '{DAV:}resourcetype': None, '{DAV:}getetag': '"ebeaa75c41064ef35f8598872d9da08d"', '{DAV:}getcontenttype': 'text/plain'})]

@MuellerSeb
Copy link

The provided documentation snippet does not work for me. I have to explicitly call anon_login with token, password.

Without anon_login:

url = os.environ.get("PUBLIC_SHARE_URL")
password = os.environ.get("PUBLIC_SHARE_PASSWORD")
oc = owncloud.Client.from_public_link(url, password=password, debug=True)

Got the exact same problem: #264. It was a typo in the documentation and it should be folder_password=password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants