Как работать с 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}'