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>
Related
I'm trying to send an "on" signal to a wemo smart plug. I want to send the signal from the linux command line. I know that the request is supposed to look like what I've included below, but I'm not sure what syntax to use. I tried using cURL, but couldn't quite seem to figure it out. Any help would be super appreciated!
POST /upnp/control/basicevent1
SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"
Content-Type: text/xml; charset="utf-8"
Accept: */*
User-Agent: PostmanRuntime/7.15.2
Cache-Control: no-cache
Host: 192.168.1.116:49153
Accept-Encoding: gzip, deflate
Content-Length: 306
Connection: keep-alive
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1">
<BinaryState>0</BinaryState>
</u:SetBinaryState>
</s:Body>
</s:Envelope>
I tried putting each of the headers in quotes after a "-H" but then I wasn't sure what to do with the headers that are already quoted. Also, it appeared to be still sending to port 80 even though I included the host header with a different port?
As far as I know, the plug has an IP address but no web address.
Post method have two part (header & body).
You should run cURL command like that:
Send Header:
curl -X POST -H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' -H 'Content-Type: text/xml; charset="utf-8"' http://192.168.1.116:49153/upnp/control/basicevent1
With this method, you can head multi header POST.
Send body POST:
And also with that command you can send POST body:
curl -X POST -F '<?xml version="1.0" encoding="utf-8"?>...' http://192.168.1.116:49153/upnp/control/basicevent1
Also, they're available at the following links:
How to send body POST ,
How to send header POST
Command you want at single line:
curl -X POST -H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' -H 'Content-Type: text/xml; charset="utf-8"' -H 'Accept: */*' -H 'User-Agent: PostmanRuntime/7.15.2' -H 'Cache-Control: no-cache' -H 'Host: 192.168.1.116:49153' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Length: 306' -H 'Connection: keep-alive' -F '<?xml version="1.0" encoding="utf-8"?>\n<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">\n <s:Body>\n <u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1">\n <BinaryState>0</BinaryState>\n </u:SetBinaryState>\n </s:Body>\n</s:Envelope>' http://192.168.1.116:49153/upnp/control/basicevent1
alias
If you think this is a long command, you can set as alias.
For e.g:
alias myPersonalCommandLS='ls -lthra1d'
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.
How can I send POST request with a csv or a text file to the server running on a localhost using cURL.
I have tried curl -X POST -d #file.csv http://localhost:5000/upload but I get
{
"message": "The browser (or proxy) sent a request that this server could not understand."
}
My server is flask_restful API. Thanks a lot in advance.
There are many alternate ways to accomplish this. One way is
I have used the following:
curl -F ‘data=#<file_location>’ <URL>
Eg. curl -F data=#data.csv localhost:5000/h
Your command can also be changed slightly like this
curl -X POST -H 'Content-Type: text/csv' -d #file.csv http://localhost:5000/upload
The above is one of the many ways.It can be sent either as a part of form or data, or multipart, etc. You can refer Medium Post
Curl's default Content-Type is application/x-www-form-urlencoded so your problem is probably that the data you are POSTing is not actually form data. It might work if you set the content type header properly:
-H "Content-Type: text/csv"
Though it does depend on the server.
Before you post this as a duplicate; I've tried many of the suggestions I found around SO.
So far I've been using postman to post data to a Java web service. That works great as follows:
I now want to do the same using curl, so I tried it using the following ways:
$ curl -X POST --data "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data "#/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "#/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
Unfortunately, all of those show an empty raw body on the receiving side.
Does anybody know what I'm doing wrong here? How is my curl request different from my postman request? All tips are welcome!
curl's --data will by default send Content-Type: application/x-www-form-urlencoded in the request header. However, when using Postman's raw body mode, Postman sends Content-Type: text/plain in the request header.
So to achieve the same thing as Postman, specify -H "Content-Type: text/plain" for curl:
curl -X POST -H "Content-Type: text/plain" --data "this is raw data" http://78.41.xx.xx:7778/
Note that if you want to watch the full request sent by Postman, you can enable debugging for packed app. Check this link for all instructions. Then you can inspect the app (right-click in Postman) and view all requests sent from Postman in the network tab :
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>