Verified Commit 573b24f8 authored by Renato Alves's avatar Renato Alves 🌱
Browse files

Add post about programmatic access to

parent cb76c76c
Pipeline #21268 passed with stages
in 8 seconds
date: 2021-03-31
featured_image: "images/2021-03-31/"
tags: ["Renato Alves", "Bio-IT", "Owncloud", "Command-line"]
title: "Uploading to ownCloud (@EMBL) from command-line"
omit_header_text: true
EMBL provides an [ownCloud][owncloud] server with (as of March 2021) 50GiB of storage for every EMBL user.
To access it navigate to [][ocembl] and login using your EMBL credentials.
## An alternative to Google Docs/Drive
You can use this system much like [Google Docs or Google Drive][oc-google-howto] by storing and sharing files or using the built in tools to edit documents.
## Programmatic access
Besides public and private links for download and upload,
Owncloud provides a [WebDAV][webdav] interface that can be used for programmatic access.
You can find the WebDAV URL for your user by logging in to [][ocembl] and clicking the **Settings** option in the bottom left corner of the screen.
![WebDAV URL](../../images/2021-03-31/webdav-url.png)
### Programmatic upload
Lets assume we have a file called `hello.txt` that we want to upload to a folder called `uploads` in your [][ocembl] account.
We can start by creating the test file.
echo 'Hello Owncloud!' > hello.txt
As we will need to use your account password, we can use the `read` command to type it without accidentally adding it to the shell history.
Execute the next command, type your password and press Enter/Return.
read -s PASSWORD
You can confirm that the command worked by executing the next command that will display your password on screen:
In order to upload the file into a `uploads` folder we must first create the folder.
This can be achieved using the `MKCOL` instruction using `curl` and your WebDAV URL.
curl -X MKCOL -u username:$PASSWORD ""
where `username` should be your EMBL username,
`...` should be a unique identifier part of the WebDAV URL you copied above
and the `/uploads` part indicates the folder name we want to create.
If you received an error in this step, verify that your username, password and WebDAV URL are correct.
Once successful, if you refresh your browser you should now see an `uploads` folder.
We are now ready to upload our `hello.txt` file which we can do with:
curl -X PUT -u username:$PASSWORD "" --data-binary @"hello.txt"
notice that we now use a `PUT` instruction instead of `MKCOL`,
the URL ends in `uploads/hello-in-owncloud.txt` to indicate the folder and filename we want to create
and `@"hello.txt"` indicates the name of the file in your computer.
If successful you should now see a `hello-in-owncloud.txt` file inside the `uploads` folder when visiting [][ocembl].
Finally to clear the password stored in `$PASSWORD` simply close the shell or execute:
### Additional WebDAV instructions
Besides `MKCOL` and `PUT`, WebDAV supports `MOVE` and `PROPFIND` instructions.
You can read more about these in the [ownCloud official documentation][ocdocs].
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment