Articles on: API

Using the API Leviia Drive - Curl

Files can be sent and received directly from the command line (e.g. for scripting).

Curl installation :


Whatever your platform, there's a good chance that the Curl binary will be ported for it, so install it : https://curl.se/download.html.

Once Curl is installed, use the following commands, replacing USER with your user name and PASSWORD with your application password.

Send a file to Leviia :


curl -X PUT "https://cloud.leviia.com/remote.php/dav/files/USER/FICHIER" -u 'USER:PASSWORD' -T /PATH/VERS/MON/FICHIER

Download a file from Leviia :


curl -o /MIN/VERS/MON/FICHIER https://cloud.leviia.com/remote.php/dav/files/USER/FICHIER -u 'USER:PASSWORD'

Delete a file on Leviia :


curl -X DELETE https://cloud.leviia.com/remote.php/dav/files/USER/FICHIER -u 'USER:PASSWORD'

List the contents of a directory :


To list the contents of a directory, include this code in your script.
#!/bin/bash

list_folder () {
  folder=$1
  domain="cloud.leviia.com"
  path='<d:href>/remote.php/webdav'
  suffix='</d:href>'
  prefix=$path$folder

  curl -s -X PROPFIND "https://$domain/remote.php/webdav$folder" -u 'USER:PASSWORD' | xmllint --format - | grep href | awk '{$1=$1};1' | cut -c$((${#prefix}+1))- | rev | cut -c$((${#suffix}+1))- | grep . | rev | while read; do echo -e ${REPLY//%/\\x}; done
}

Then use the list_folder function with the directory path as argument (starting and ending with "/").

For example: list_folder / or list_folder /Photos/.

Example of a BASH script :


Here's an example of a BASH script used to save a website on Leviia._

#!/usr/bin/env bash

user='USER'
password='PASSWORD
today=$(date +%d-%m-%y)
url="https://cloud.leviia.com/remote.php/dav/files/$user"

#BACKUP SQL DATABASE
echo "Start database dump".
mysqldump --single-transaction=TRUE -uroot --all-databases > "/tmp/db-$today".sql
echo "database dump OK"

#BACKUP WEB FOLDER
echo "Start web folder compression".
tar czf "/tmp/dossier-$today".tar.gz /var/www/html/
echo "Web folder compressed

echo "Send database to Leviia".
curl -X PUT "$url/db-$today.sql" -u $user:$password -T "/tmp/db-$today".sql

echo "Send web folder to Leviia"
curl -X PUT "$url/folder-$today.tar.gz" -u $user:$password -T "/tmp/folder-$today".tar.gz




It's perfectly possible to use Curl to send documents via a public link.

Start by creating a public link.

The link should look like this: https://cloud.leviia.com/s/56qFXNKDGJn2nHY where 56qFXNKDGJn2nHY is the token. This is the token you'll need.

To send files, use :

curl -X PUT "https://cloud.leviia.com//public.php/webdav/DOCUMENT" -u "$TOKEN:$PASSWORD" -T /MIN/VERS/DOCUMENT

Replace $TOKEN and $PASSWORD with your token and share password (leave blank if no password exists).

Updated on: 05/01/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!