I have a windows machine, where I have shared a location and made it open through browser using https. Something like this- "https://my-windows/test".

I am writing a shell script which will post a file to this machine/url. I am able to download file using curl from this location but when I post/put, it gives me error. It says that I am trying to put it in a folder and expected is a file.

I don't want to over write an existing file. I want to create a new file. Is this possible with curl? I am writing this shell script in Linux box and destination is a windows box.

I tried following:

1. curl -D- -u user:pass -X POST --data "@test.txt" https://my-windows/test

HTTP/1.1 200 Connection established

HTTP/1.1 405 Method Not Allowed

2. curl -D- -u user:pass -X PUT --data "@test.txt" https://my-windows/test

  "errors" : [ {
    "status" : 500,
    "message" : "Expected a file but found a folder

3. curl -D- -u user:pass -F "file=@test.txt;filename=nameinpost" https://my-windows/test

HTTP/1.1 200 Connection established

HTTP/1.1 100 Continue

HTTP/1.1 405 Method Not Allowed
Content-Length: 0
  • 1
    what does this do? curl -D- -u user:pass -X PUT --data "@test.txt" https://my-windows/test/test.txt
    – clk
    Apr 5 '17 at 13:13
  • I am passing my credentials(username and password) and telling that I am using PUT.
    – Raji
    Apr 5 '17 at 13:35
  • I mean including the file name in the path. https://my-windows/test/test.txt instead of https://my-windows/test.
    – clk
    Apr 5 '17 at 14:03
  • OhI Sorry, did not read completely. my-windows/test/test.txt instead of my-windows/test works. It created test.txt. Thank you sooo much! I was so stuck with this. Thanks a ton!!!
    – Raji
    Apr 5 '17 at 14:17

The error in the second message suggests that you need to include the file name, like this:

curl -D- -u user:pass -X PUT --data "@test.txt" https://my-windows/test/test.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.