ラベル Nextcloud の投稿を表示しています。 すべての投稿を表示
ラベル Nextcloud の投稿を表示しています。 すべての投稿を表示

2022年9月18日日曜日

Raspberry Pi OS(Raspbian Bullseye)にrcloneをインストールする

rcloneでクラウドストレージやストレージサーバ間でファイルを管理したり・同期する事ができます。

インストール方法

以下のコマンドでrcloneをインストールします。
sudo apt-get install curl

curl https://rclone.org/install.sh | sudo bash

リモート構成の登録方法

rclone configコマンドを使用して、Nextcloudをリモートストレージとして登録します。
rclone config

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config

n/s/q> n ※新しいリモート構成を作成する
name> nextcloud ※任意のリモート構成の名称を入力

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon Drive
   \ (amazon cloud drive)
 5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, China Mobile, Cloudflare, ArvanCloud, Digital Ocean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS and Wasabi
   \ (s3)
 6 / Backblaze B2
   \ (b2)
 7 / Better checksums for other remotes
   \ (hasher)
 8 / Box
   \ (box)
 9 / Cache a remote
   \ (cache)
10 / Citrix Sharefile
   \ (sharefile)
11 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / Dropbox
   \ (dropbox)
14 / Encrypt/Decrypt a remote
   \ (crypt)
15 / Enterprise File Fabric
   \ (filefabric)
16 / FTP
   \ (ftp)
17 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
18 / Google Drive
   \ (drive)
19 / Google Photos
   \ (google photos)
20 / HTTP
   \ (http)
21 / Hadoop distributed file system
   \ (hdfs)
22 / HiDrive
   \ (hidrive)
23 / Hubic
   \ (hubic)
24 / In memory object storage system.
   \ (memory)
25 / Internet Archive
   \ (internetarchive)
26 / Jottacloud
   \ (jottacloud)
27 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
28 / Local Disk
   \ (local)
29 / Mail.ru Cloud
   \ (mailru)
30 / Mega
   \ (mega)
31 / Microsoft Azure Blob Storage
   \ (azureblob)
32 / Microsoft OneDrive
   \ (onedrive)
33 / OpenDrive
   \ (opendrive)
34 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ (swift)
35 / Pcloud
   \ (pcloud)
36 / Put.io
   \ (putio)
37 / QingCloud Object Storage
   \ (qingstor)
38 / SSH/SFTP
   \ (sftp)
39 / Sia Decentralized Cloud
   \ (sia)
40 / Storj Decentralized Cloud Storage
   \ (storj)
41 / Sugarsync
   \ (sugarsync)
42 / Transparently chunk/split large files
   \ (chunker)
43 / Union merges the contents of several upstream fs
   \ (union)
44 / Uptobox
   \ (uptobox)
45 / WebDAV
   \ (webdav)
46 / Yandex Disk
   \ (yandex)
47 / Zoho
   \ (zoho)
48 / premiumize.me
   \ (premiumizeme)
49 / seafile
   \ (seafile)

Storage> 45 ※Nextcloudなどは45 Webdavを選択します
** See help for webdav backend at: https://rclone.org/webdav/ **

Option url.
URL of http host to connect to.
E.g. https://example.com.
Enter a value.
url> http://<ホスト名またはIP>:<ポート>/nextcloud/remote.php/dav/files/admin/ ※webルートにnextcloudがインストールされている場合はhttp://<ホスト名またはIP>:<ポート>/remote.php/dav/files/admin/になります。

Option vendor.
Name of the WebDAV site/service/software you are using.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / Nextcloud
   \ (nextcloud)
 2 / Owncloud
   \ (owncloud)
 3 / Sharepoint Online, authenticated by Microsoft account
   \ (sharepoint)
 4 / Sharepoint with NTLM authentication, usually self-hosted or on-premises
   \ (sharepoint-ntlm)
 5 / Other site/service or software
   \ (other)

vendor> 1 ※Nextcloudの場合は1を入力します

Option user.
User name.
In case NTLM authentication is used, the username should be in the format 'Domain\User'.
Enter a value. Press Enter to leave empty.
user> admin ※ Nextcloudのユーザ名を入力します


Option pass.
Password.
Choose an alternative below. Press Enter for the default (n).
y) Yes, type in my own password
g) Generate random password
n) No, leave this optional password blank (default)
y/g/n> y ※ パスワードを入力するにはyを入力します

Enter the password:
password: ※パスワードを入力します
Confirm the password:
password: ※ パスワードを確認入力します

Option bearer_token.
Bearer token instead of user/pass (e.g. a Macaroon).
Enter a value. Press Enter to leave empty.
bearer_token> ※ 何も入力せずエンターキーを押します

Edit advanced config?
y) Yes
n) No (default)
y/n> ※ nを入力します


Configuration complete.
Options:
- type: webdav
- url: http://<ホスト名またはIP>:<ポート>/nextcloud/remote.php/dav/files/admin/
- vendor: nextcloud
- user: admin
- pass: *** ENCRYPTED ***
Keep this "nextcloud" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y ※ yで保存します

Current remotes:

Name                 Type
====                 ====
nextcloud            webdav

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q ※抜ける場合はqを入力します

ローカルファイルの同期方法

以下のコマンドで、ローカルの~/testの内容をnextcloudのtestフォルダに同期します
rclone --verbose sync ~/test nextcloud:/test
※~/testに何もない状態だと、nextcloud側の/textは全て消されるので注意

2022年4月1日金曜日

FeedReaderからNextcloudのNewsアプリを利用する

FeedReaderからNextcloudのNewsアプリを利用する事ができます。FeedReaderからNextcloudのNewsアプリを利用するには、以下の手順を実行します。

設定方法

1. 以下のページを参照して、NextcloudにNewsアプリをインストールします。
NextcloudにRSSリーダー機能を追加するNewsアプリを追加する

2. FeedReaderインストール後にフィードサービス選択時に「Nextcloud News」を選択します。

3. NextcoudのURL、ユーザ名、パスワードを入力します。

4. Nextcloud Newsアプリと内容が表示されることを確認します。

関連情報

・FeedReaderのwebサイト
https://jangernert.github.io/FeedReader/

2022年3月19日土曜日

Python WebDAV Client 3を使用してNextcloud上のファイルを削除する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルを削除する事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAV上のファイルを削除します。以下のサンプルプログラムを保存して、実行します。
wdc3_clean.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツの削除
remotepath='Photos/Frog2.jpg'
client.clean(remotepath)

・実行コマンド
python3 wdc3_clean.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月18日金曜日

Python WebDAV Client 3を使用してNextcloud上に指定ディレクトリ上のファイルをアップロードする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、指定ディレクトリ上のファイルをアップロードする事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAV上に指定ディレクトリ上のファイルをアップロードします。以下のサンプルプログラムを保存して、実行します。
※アップロード先にあるコンテンツは削除されます
wdc3_upload_directory.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのアップロード
remotepath='サンプル'
localpath='/tmp/Photos' # あらかじめアップロードするファイルなどは準備してください
client.upload_directory(remotepath, localpath)

・実行コマンド
python3 wdc3_upload_directory.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月17日木曜日

Python WebDAV Client 3を使用してNextcloud上の指定ディレクトリ配下のファイルをダウンロードする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、指定ディレクトリ配下のファイルをダウンロードする事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAV上の指定ディレクトリ配下のファイルをダウンロードします。以下のサンプルプログラムを保存して、実行します。
wdc3_download_directory.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのダウンロード
remotepath='Photos'
localpath='/tmp/Photos'
client.download_directory(remotepath, localpath)

・実行コマンド
python3 wdc3_download_directory.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月16日水曜日

n8n.ioでLocal File Triggerノードを使用して、ディレクトリ監視をしてファイル作成時にNextcloudにファイルをアップロードする

n8n.ioでLocal File Triggerノードを使用して、ディレクトリ監視をしてファイル作成時にNextcloudにファイルをアップロードするには、以下のフロー作成手順を実行します。

フロー作成手順

1. Local File Trigger Nodeを追加します
ディレクトリを監視する場合は「Trigger on」で「Changes Involving a Specific Folder」を選択し、「Folder to Watch」に監視したいフォルダのパスを入力します。
Watch forでファイルの追加を検知したい場合は「File Added」を選択します。

2. Read Binary File Nodeを追加します
File PathでAdd expressionを選択して「{{$node["Local File Trigger"].json["path"]}}」を入力します。
Property Nameは「data」を設定します。

3. Nextcloud Nodeを追加して、以下のパラメータを設定します
Credential for NextCloud API: ドロップダウンリストから「Create New」を選択してWeb DAV URLには「dav://サーバ名またはIPアドレス:ポート番号/remote.php/dav/files/ユーザID」を設定し、UserにはユーザID、Passwordにはパスワードを入力します
Authentication: Access Token
Resource: File
Operation: Upload
File Path: Add expressionを選択して、「{{"/" + $node["Local File Trigger"].json["path"].replace(/^.*[\\\/]/, '')}}」を入力します
Binary Data: ON状態にします
Binary Property: data

4. (アップロード後に元ファイルを削除したい場合)Execute Command Nodeを追加して、以下のパラメータを設定します
CommandフィールでAdd expressionを選択して「rm -f {{$node["Local File Trigger"].json["path"]}}」を入力します

5. Workflow画面上部のActivateをオン状態にします。
※結果はExecutionsに表示されます。

〇フロー図

Python WebDAV Client 3を使用してNextcloud上のファイルをコピーする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルをコピーする事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAV上のファイルをコピーします。以下のサンプルプログラムを保存して、実行します。
wdc3_copy.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのコピー
remotepath_from='Photos/Frog.jpg'
remotepath_to='Photos/Frog2.jpg'
client.copy(remotepath_from, remotepath_to)

・実行コマンド
python3 wdc3_copy.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月15日火曜日

Python WebDAV Client 3を使用してNextcloud上のファイルをダウンロードする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルをダウンロードする事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAV上のファイルをダウンロードします。以下のサンプルプログラムを保存して、実行します。
wdc3_download.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのダウンロード
remotepath='Nextcloud.png'
localpath='/tmp/Nextcloud.png'
client.download(remotepath, localpath)

・実行コマンド
python3 wdc3_download.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月14日月曜日

Pythonを使用して、Nextcloudのインストール済みアプリ一覧を取得する

Pythonを使用して、Nextcloudのインストール済みアプリ一覧を取得するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、インストールしたアプリ一覧を表示します
nc_list_apps.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'


baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/apps"

headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}

response = requests.get(
  baseuri,
  headers=headers)
print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_list_apps.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Python WebDAV Client 3を使用してNextcloud上にディレクトリを作成する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ディレクトリを作成する事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAV上にディレクトリを作成します。以下のサンプルプログラムを保存して、実行します。
wdc3_mkdir.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# ディレクトリの作成
result = client.mkdir("サンプル")
print(result)
result = client.mkdir("サンプル/音楽")
print(result)

・実行コマンド
python3 wdc3_mkdir.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月13日日曜日

Pythonを使用して、Nextcloudのグループを削除する

Pythonを使用して、Nextcloudのグループを削除するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定グループを削除します
nc_delete_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# 削除するグループ
userid = 'テストグループ'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups/" + userid
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
response = requests.delete(
  baseuri,
  headers=headers)
print(response.content)

・実行コマンド
python3 nc_delete_group.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Python WebDAV Client 3を使用してNextcloudのファイルを列挙する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルを列挙する事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントを使用してWebDAVディレクトリの内容を列挙します。以下のサンプルプログラムを保存して、実行します。
wdc3_list.py
from webdav3.client import Client

dav_user='testuser'
dav_password='testpassword'
dav_server='mynextcloud:8080'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

files = client.list(get_info=True)
for file in files:
        if file['isdir'] == True:
                print("directory:" + file['path'])
        else:
                print("file:" + file['path'])

・実行コマンド
python3 wdc3_list.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月12日土曜日

Pythonを使用して、Nextcloudのグループのsubadminを取得する

Pythonを使用して、Nextcloudのグループのsubadminを取得するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定グループのsubadminを返します
nc_subadmins_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# メンバーを取得したいグループ
groupid="サンプルグループ"
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups/" + groupid + "/subadmins"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
response = requests.get(
  baseuri,
  headers=headers)
print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_subadmins_group.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Python WebDAV Client 3を使用してNextcloud上のファイルの情報を取得する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルの情報を取得する事が出来ます。

インストール手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順

WebDAVクライアントのinfoメソッドを使用してWebDAV上のファイルの情報を取得します。以下のサンプルプログラムを保存して、実行します。
wdc3_info.py
from webdav3.client import Client

dav_user='testuser'
dav_password='testpassword'
dav_server='yourserver:8080'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツの情報を取得
remotepath='Photos/Library.jpg'
result = client.info(remotepath)
for key,value in result.items():
  print("{}={}".format(key, value))

・実行コマンド
python3 wdc3_info.py

関連情報

・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関するほかの記事は以下のまとめページを参照してください。
Nextcloudのまとめ

2022年3月11日金曜日

Pythonを使用して、Nextcloudのグループメンバーを取得する

Pythonを使用して、Nextcloudのグループメンバーを取得するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定グループのメンバーを返します
nc_members_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# メンバーを取得したいグループ
groupid="サンプルグループ"
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups/" + groupid
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
response = requests.get(
  baseuri,
  headers=headers)
print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_members_group.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月10日木曜日

Pythonを使用して、Nextcloudのグループを作成する

Pythonを使用して、Nextcloudのグループを作成するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、グループを作成します。
nc_create_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
# 作成するグループIDを指定します
params  = {'groupid': 'テストグループ'}
response = requests.post(
  baseuri,
  params=params,
  headers=headers)
print(response.content)

・実行コマンド
python3 nc_create_group.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月9日水曜日

Pythonを使用して、Nextcloudのグループを検索する

Pythonを使用して、Nextcloudのグループを検索するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定文字列を含むグループを返します(パラメータをなしにすると全グループ)。
nc_search_groups.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
#params  = {} # 全グループの場合
params  = {'search': 'サンプル'}
response = requests.get(
  baseuri,
  params=params,
  headers=headers)
#print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_search_groups.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月8日火曜日

Pythonを使用して、Nextcloudの指定ユーザをsubadminから降格する

Pythonを使用して、Nextcloudの指定ユーザをsubadminから降格するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザをsubadminから降格します。
nc_denote_subadmin.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# subadminから降格するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/subadmins".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # subadmin降格対象のグループ
}
response = requests.delete(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_denote_subadmin.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月7日月曜日

Pythonを使用して、Nextcloudの指定ユーザをsubadminにする

Pythonを使用して、Nextcloudの指定ユーザをsubadminにするには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザをsubadminに昇格します。
nc_promote_subadmin.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# subadminに昇格するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/subadmins".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # subadmin昇格対象のグループ
}
response = requests.post(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_promote_subadmin.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月6日日曜日

Pythonを使用して、Nextcloudのユーザの所属グループを削除する

Pythonを使用して、Nextcloudのユーザの所属グループを削除するには、以下の手順を実行します

実行手順

1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザの所属グループを削除します。
nc_user_remove_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# 所属グループを削除するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/groups".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # 削除する所属グループ
}
response = requests.delete(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_user_remove_group.py

関連情報

・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ