如何在curl或WebDav中递归创建目录?

如何在curl或WebDav中递归创建目录?,curl,recursion,webdav,nextcloud,Curl,Recursion,Webdav,Nextcloud,我想将文件上载到我的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" 如

我想将文件上载到我的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_目录
只包含一个目录,它就可以工作。但是,如果此变量包含例如
/root/deep/deep
deep
不存在,则我得到以下错误:

<?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>

Sabre\DAV\Exception\Conflict
父节点不存在
第二个命令引发此错误:

<?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>

Sabre\DAV\Exception\NotFound
找不到名为//test的文件
那么我如何创建递归目录来上传文件呢


谢谢。

没有创建递归目录的选项,因此我将变量拆分为一个数组,并逐个创建目录

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"

IFS='/'read-r-a array没有创建递归目录的选项,因此我将变量拆分为一个数组并逐个创建目录

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"

IFS='/'read-r-a数组这种行为没有方法

阿普罗奇:


您需要创建自己的递归函数,该函数遍历目录路径并逐个创建它们,就像上面的ilustrate一样。

没有实现该行为的方法

阿普罗奇:


您需要创建自己的递归函数,该函数遍历目录路径并逐个创建它们,就像上面的ilustrate一样。

好的,您可以逐个创建它们。@JulianReschke:谢谢。我将经历一个循环。好吧,你一个接一个地创建它们。@JulianReschke:谢谢。我要做一个循环。