Як працювати з WEBDAV через CURL

Є наступні данні:

  • Webdav URL: http://example.com/webdav
  • Username: user
  • Password: pass

Дії

Прочитати файли та папки

curl 'http://example.com/webdav'

Створити нову папку

curl -X MKCOL 'http://example.com/webdav/new_folder'

Завантажити файл

curl -T '/path/to/local/file.txt' 'http://example.com/webdav/test/new_name.txt'

Перейменування файла

curl -X MOVE --header 'Destination:http://example.org/webdav/new.txt' 'http://example.com/webdav/old.txt'

Видалити Файл/Папку

Файл:

curl -X DELETE 'http://example.com/webdav/test.txt'

Папка:

curl -X DELETE 'http://example.com/webdav/test'

Перелік файлів у папці

curl -i -X PROPFIND http://example.com/webdav/ --upload-file - -H "Depth: 1" <<end
<?xml version="1.0"?>
<a:propfind xmlns:a="DAV:">
<a:prop><a:resourcetype/></a:prop>
</a:propfind>
end

Опції

Аутентифікація

Basic:

curl --basic --user 'user:pass' 'http://example.com/webdav'

Digest:

curl --digest --user 'user:pass' 'http://example.com/webdav'

нехай cURL вибирає:

curl --anyauth --user 'user:pass' 'http://example.com/webdav'

Отримати код відповіді

curl -X DELETE 'http://example.com/webdav/test' -sw '%{http_code}'