Skip to content

Commit 9d16a7d

Browse files
committed
added nextcloud upload
1 parent 3ac3b4a commit 9d16a7d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

_posts/2017-11-13-nexcloud-upload.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
layout: post
3+
title: Dateiupload in Nextcloud aus der Konsole
4+
date: 2017-03-13 19:57:38 +0100
5+
categories: owncloud nextcloud share password bash console cli
6+
---
7+
Mit diesem Bash-Script kannst du Dateien mit einem einzigen Befehl in Nextcloud hochladen und Passwortgeschützt freigeben.
8+
9+
# Das Script
10+
11+
{% highlight bash %}
12+
function upload() {
13+
# TODO: hier musst du deine Nextcloud Zugansdaten eintragen
14+
nc_user="benutzername"
15+
nc_password="supergeheimespasswort"
16+
nc_url="mein.nextcloud.example.com"
17+
18+
file="$1"
19+
file_save=$(echo -n $file | tr -c '[A-z0-9_\-\.]' '_')
20+
21+
# Upload nach nextcloud
22+
echo Uploading "$file" to "$file_save" ...
23+
curl -X PUT -u "$nc_user:$nc_password" https://$nc_url/remote.php/webdav/Kundendaten/${file_save} --data-binary "@$file"
24+
25+
password=$(dd if=/dev/urandom bs=1M count=1 2> /dev/null | tr -dc "A-Za-z0-9" | head -c 8)
26+
curl -X POST -H "OCS-APIRequest: true" -d "true" -u "$nc_user:$nc_password" \
27+
--data "path=/Kundendaten/${file_save}&shareType=3&password=${password}" \
28+
https://$nc_url/ocs/v1.php/apps/files_sharing/api/v1/shares \
29+
| grep url | sed 's/\s*<\/*url>//g' | sed 's/^/URL: /'
30+
echo Passwort: $password
31+
32+
}
33+
{% endhighlight %}
34+
35+
# Beispiel
36+
37+
{% highlight bash %}
38+
upload /tmp/testdatei
39+
# Uploading /tmp/testdatei to _tmp_testdatei ...
40+
# % Total % Received % Xferd Average Speed Time Time Time Current
41+
# Dload Upload Total Spent Left Speed
42+
# 100 1241 100 1174 100 67 1174 67 0:00:01 0:00:01 --:--:-- 1064
43+
# URL: https://owncloud.united-gameserver.de/index.php/s/D2mXHBZ2heEKaXR
44+
# Passwort: ycjGVNm4
45+
{% endhighlight %}

0 commit comments

Comments
 (0)