【问题标题】:How to create directories recursively in curl or WebDav?如何在 curl 或 WebDav 中递归创建目录?
【发布时间】:2017-08-13 22:46:45
【问题描述】:

我想将文件上传到我的 nextcloud 服务器。问题是我有一个错误。第一个 curl 命令应该创建目录。

curl -u "$USER":"$PW" -X MKCOL "https://MYSERVER/remote.php/dav/files/$USER/$MANY_DIRECTORIES"
curl -u "$USER":"$PW" -T "$FILE" "https://MYSERVER/remote.php/dav/files/$USER/$MANY_DIRECTORIES/$FILE"

如果$MANY_DIRECTORIES 只包含一个目录,它可以工作。但是如果这个变量包含例如/root/deep/deeperdeep 不存在我收到此错误:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\Conflict</s:exception>
  <s:message>Parent node does not exist</s:message>
</d:error>

第二个命令抛出这个错误:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\NotFound</s:exception>
  <s:message>File with name //test could not be located</s:message>
</d:error>

那么如何创建递归目录来上传文件呢?

谢谢。

【问题讨论】:

  • 好吧,你一个一个地创建它们。
  • @JulianReschke:谢谢。我会循环一下。

标签: curl recursion webdav nextcloud


【解决方案1】:

没有创建递归目录的选项,所以我把变量拆分成一个数组,一个一个地创建目录。

IFS='/' read -r -a array <<<"$2"
for el in "${array[@]}"
do
        TEMP=$TEMP/$el
        curl -u "$USER:$PW" \
        -X MKCOL \
        "https://MYSERVER/remote.php/dav/files/$USER$TEMP"
done

curl -u "$USER:$PW" \
         -T "$1" "https://MYSERVER/remote.php/dav/files/$USER/$2/$1"

【讨论】:

    【解决方案2】:

    这种行为没有办法!

    方法:

    您需要创建自己的递归函数,遍历目录路径并一一创建,如上面answer 中的cy221 ilustrate。

    【讨论】:

      猜你喜欢
      • 2011-09-08
      • 2011-04-10
      • 2011-10-10
      • 1970-01-01
      • 2012-06-12
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多