I need to check if I have a file in my Nextcloud before uploading another one (same name). I haven't found any way to do this using curl (the command I'm using to upload the new file). So, searching in the client API of Nextcloud I've found the webDAV search.
I've tried to use it before the upload to check if the file exists. This is what I've achieved:
curl -u myUser:myPass 'https://nextcloud.customExample.com/remote.php/dav/' -X SEARCH -u myUser:myPass -H "content-Type: text/xml" --data '<?xml version="1.0" encoding="UTF-8"?>
<d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:basicsearch>
<d:select>
<d:prop>
<d:displayname/>
</d:prop>
</d:select>
<d:from>
<d:scope>
<d:href>/files/myFolder/myFile.apk</d:href>
<d:depth>infinity</d:depth>
</d:scope>
</d:from>
<d:where>
<d:like>
<d:prop>
<d:getcontenttype/>
</d:prop>
<d:literal>text/%</d:literal>
</d:like>
</d:where>
<d:orderby>
<d:prop>
<oc:size/>
</d:prop>
<d:ascending/>
</d:orderby>
</d:basicsearch>
</d:searchrequest>'
I'm getting this error when executing:
<?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>Principal with name myFolder not found</s:message>
</d:error>
The folder myFolder is, as I see, in the root of my Nextcloud. I don’t know if I need something more to add before it (as I added “files”).
The user has permissions and using the curl command to upload the file with this same user is working.
After all I've found an easier way to check if a file exists:
url='http://example.com/index.html'
if ( curl -o/dev/null -sfI "$url" ); then
echo "URL exists"
else
echo "URL does not exist"
fi
To that curl command you can add the --user parameter if you need authentication.
I've found it here.
Related
I am using curl - u user:password -X post method in shell script to trigger my Jenkins jobs externally. While using this method I am providing my credentials to access Jenkins.
Is there any way to hide or encrypt credentials.?
Curl with -u does not support encrypt username and password but you can do it in different way to hide username and password
Create an environment variable Use that on your curl command like below :
export USERNAME=""
export PASSWORD=""
after that
curl -u $USERNAME:$PASSWORD -X POST ...
Make use of .netrc file with curl command.
curl command option for .netrc file
-n, --netrc Must read .netrc for user name and password
--netrc-file <filename> Specify FILE for netrc
Steps to use .netrc
Create a .netrc file on your home directory (~) with content
machine jenkins.url
login username
password jenkinsTokenOrPassword
invoke curl command
curl -n -X POST ....
Note. If you don't want to keep your .netrc file on your home directory ~ , than place it somewhere else but make sure let curl know about the location like curl --netrc-file /path/to/.netrc -X POST ...
http://filedownloads.co.in/downloads/domain/October
In the above given web directory there are approx 30 zip file like
http://filedownloads.co.in/downloads/domain/October/2017-10-09hhwerahhqw_country-specific-database.zip
or
http://filedownloads.co.in/downloads/domain/October/2017-10-20weroiunewd_country-specific-database.zip
I want to download all file of that directory. I have tried all options available on stack-overflow related to my questions but every time i get the same Error 403: forbidden.
I have tried the following commands :
wget --user-agent="Mozilla" -r -np -A.zip http://filedownloads.co.in/downloads/domain/October
and
wget -r -l1 -H -t1 -nd -N -np -A.zip -erobots=off http://filedownloads.co.in/downloads/domain/October/
and
wget -U firefox -r -np http://filedownloads.co.in/downloads/domain/October/
I've tried to visit your link using browser and received the same "Forbidden" message.
Try to open the link in Private window and see what happens.
It's quite possible that you are logged in on this site, so your browser has cookies which allow you to view this directory.
If so, you will need to find out these cookies and specify them too in wget so it can access the protected resource.
I have a cURL call that I'm trying to use to send file data to a remote server.
curl -X POST -u username:password -d 'data=#/path/to/file.ext&version=2&action=Parse' http://fqdn.to.server.i.control/Parser.cgi
curl -X POST -u username:password -d 'data=#localFile.ext&version=2&action=Parse' http://fqdn.to.server.i.control/Parser.cgi
cat file.ext | curl -X POST -u username:password -d 'data=#-&version=2&action=Parse' http://fqdn.to.server.i.control/Parser.cgi
The file contents are URI encoded already. Using Perl and CGI on the server side.
My problem is that when the server tries to access that "data" line, value I have is only "file.ext" - the path is stripped out and the file's contents are not used ($cgi->param("data") is just "file.ext", "localFile.ext" or "-" respectively).
Any indication as to what I'm doing wrong?
#MattJacob was correct; my syntax was wrong. data=#... should have been #... and the data= portion should have been in the file. Boy am I thick.
I have written an Application, should upload some files to several mobile devices. By now, I am using dropbox, I have an App (https://www.dropbox.com/developers), so I can upload any data to the clients Dropbox.
Now I would like to switch to owncloud because of some security concerns. I already have read this:
Uploading files to an ownCloud server programatically
But unfortunately it didn't help.
I tried
curl -X PUT -u username:password "http://myserver.com/owncloud/remote.php/webdav/test" -F f=#"/tmp/test"
The file was uploaded, but there was a Problem: Some kind of Header was added to my file.
Original test-file:
test
Uploaded File:
--------------------------00c5e21306fd0b2d Content-Disposition: form-data; name="f"; filename="test" Content-Type:
application/octet-stream
Dies ist ein Test.
--------------------------00c5e21306fd0b2d--
While this is really annoying on any text-Files it is a desaster on any binary files like JPGs etc, because they can't be opened any more after uploading.
That's why, I tried the other possible way, which was described:
mischka#lappy:/tmp$ curl -X PUT -u 'username:password' "http://myserver/owncloud/remote.php/webdav/test" --data-binary #"/tmp/test"
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<s:exception>Sabre\DAV\Exception\BadRequest</s:exception>
<s:message>expected filesize 19 got 0</s:message>
</d:error>
But the result was even worse!
Can anyone tell me, what I am doing wrong?
-F means form upload, you should use --data-binary instead:
curl -X PUT -u username:password
"http://myserver.com/owncloud/remote.php/webdav/test" --data-binary #"/tmp/test"
Upload a file you have to make a PUT request to the destiny of the file for example: http://yourOwnCloudServer/remote.php/webdav/text.txt
Here is the CURL command:
curl -X PUT -u username:password "https://yourOwnCloudServer/remote.php/webdav/text.txt" -F myfile=#"/Users/gokul/Desktop/text.txt"
You can also use --data-binary for media files.
"https://yourOwnCloudServer/remote.php/webdav/image.jpg" --data-binary #"/Users/gokul/Desktop/image.jpg"
Remember to use HTTPS or in most owncloud installations will reply
<p>The document has moved here.</p>
It is possible to checkin a file to sharepoint document library using curl with the following command as mentioned in this question :
curl --ntlm --user username:password --upload-file file.txt https://mysharepointserver.com/sites/mysite/myfile.txt -k
But how to checkout the file first(using curl) from the document library?
I tried one method by passing SOAPAction checkoutfile headers and data as follows, but it had no effect eventhough the server returned response: '200 OK'
curl --ntlm --user username:password -d #soapdata.xml -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile" -H "Content-Type: text/xml; charset=utf-8" https://mysharepointserver.com/sites/mysite/myfile.txt -k
soapdata.xml contains the SOAP data needed for checkout as described by WSDL. Is there something wrong in above command or is there a simpler way to do this with CURL like the checkin case?
Found from an example that, with SOAP approach, the URL in CURL command should be the path of the sharepoint site Lists.asmx and not the URL of file to be checked out. The file URL need to be only in the pageUrl field in soapdata xml as follows:
curl --ntlm --user username:password -d #soapdata.xml -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile" -H "Content-Type: text/xml; charset=utf-8" -k -v https://mysharepointserver.com/sites/mysite/_vti_bin/Lists.asmx
where contents of soapdata.xml:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CheckOutFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<pageUrl>https://mysharepointserver.com/sites/mysite/myfile.txt</pageUrl>
<checkoutToLocal>true</checkoutToLocal>
<lastmodified/>
</CheckOutFile>
</soap:Body>
</soap:Envelope>