Use CURL to upload files to OC


#1

Hi!

I am trying to upload tarballs to OC via a script. The script first compresses files on the local server and after that I want to create a directory on OC and push the tarballs there.
The problem is that CURL fails, because https://example.com/owncloud/remote.php/webdav/ does not exist.. What else can this be?

I am using this documentation:

https://doc.owncloud.org/server/7.0/user_manual/files/files.html

Any help is much appreciated!


Trying to develop a webForm with html-php-curl
#2

Hi,

then you have some more serve issues within your environment or your webserver itself. A FAQ describing some of these issues and possible solutions are available here:


#3

Not sure what error you are experiencing but the correct way to do this is e.g. like that (of course skip cookie if you are not using XDebug in PHP Storm):

Please also mind that, that to PUT file into the directory, the directory has to exists. You need to use webdav function MKCOL similar way.

If you need, there is Python library doing that:

https://github.com/owncloud/pyocclient


#4

Thanks for your reply.. I'm getting there because I can now remotely create directory's. The last step would be to upload my tar.gz files to the folder I've created. This error shows up while trying to upload a file:

> <?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>PUT is not allowed on non-files.</s:message>
> </d:error>

Your script looks good though, so maybe that'll solve my problems!


#5

PUT works on endpoint, it means that the final path has to be file.

curl -X PUT -u $user:$pass --data-binary @"$testfile2" "http://$server/remote.php/webdav/test/zombie.jpg"

This will mean that your ownCloud address is "http://example.com/owcloud", endpoint is "remote.php/webdav", the file will be in the folder "test", and filename is "zombie.jpg".

PUT is not allowed on non-files means that you are trying to PUT (update) a non-file e.g. folder.


#6

Just stumbled over:

https://doc.owncloud.org/server/9.1/user_manual/files/access_webdav.html#accessing-files-using-curl

Wasn't aware that this is even documented :slight_smile:


#7

Thanks for your input guys, my issue is fixed and I'm able to upload via CLI now :slight_smile: