6
5

More than 1 year has passed since last update.

【Nextcloud】curlでNextcloudのAPIを操作する

Posted at

実施すること

NextcloudにCLIからcurlを使って操作をしていきます

目次

・ローカル(Desktop)に存在するファイルをアップロード
・ファイルをローカル(Desktop)にダウンロード
・ファイル名の変更
・ファイルのコピー
・ファイルの削除
・新規フォルダの作成
・ファイルの共有と共有リンク取得
・特定のユーザにファイルの共有
・ファイルの共有削除
・共有ファイルの情報取得

ローカル(Desktop)に存在するファイルをアップロード

構文
curl -X PUT -u [user名]:[パスワード] https://[ホストサーバーのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[アップロードする任意のファイル名] -T ./[ローカルからアップロードするファイル名]


ファイルをローカル(Desktop)にダウンロード

構文
 curl -X GET -u [user名]:[パスワード] https://[ホストサーバーのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[ダウンロードするファイル名] --output [保存先の任意のファイル名]


ファイル名の変更

構文
 curl -u [user名]:[パスワード] -X MOVE 'https://[ホストのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[変更前のファイル名]' -H "Destination:https://[ホストのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[変更後の任意のファイル名]"


ファイルのコピー

構文
 curl -u [user名]:[パスワード] -X COPY 'https://[ホストのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[ファイル名]' -H "Destination:[ホストのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[ファイル名]"


ファイルの削除

構文
curl -X DELETE -u [user名]:[パスワード] https://[ホストのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]/[ファイル名]


新規フォルダの作成

構文
 curl -X MKCOL -u [user名]:[パスワード] https://[ホストのIPアドレス]/remote.php/dav/files/[user名]/[フォルダ名]


ファイルの共有と共有リンク取得

構文
  curl -u [user名]:[パスワード] -X POST 'https://[ホストのIPアドレス]/ocs/v2.php/apps/files_sharing/api/v1/shares?path=/[フォルダ名]/[ファイル名]&shareType=[共有の種類]' -H "OCS-APIRequest:true"


特定のユーザにファイルの共有

構文
  curl -u [user名]:[パスワード] -X POST 'https://[ホストのIPアドレス]/ocs/v2.php/apps/files_sharing/api/v1/shares?path=/[フォルダ名]/[ファイル名]&shareType=0&shareWith=[共有対象のuser名]&permissions=[権限の種類]'  -H "OCS-APIRequest:true"


ファイルの共有削除

構文
curl -u [user名]:[パスワード] -X DELETE "https://[ホストのIPアドレス]/ocs/v2.php/apps/files_sharing/api/v1/shares/[シェアID]"  -H "OCS-APIRequest:true"


共有ファイルの情報取得

構文
curl -u [user名]:[パスワード] -X GET "https://[ホストのIPアドレス]/ocs/v2.php/apps/files_sharing/api/v1/shares"  -H "OCS-APIRequest:true"


参考記事

Nextcloudドキュメント
Nextcloud API一覧
curlオプション
curlコマンド使い方メモ

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5