1

I have a mini program/server built on one of my computers (Machine1) and I am trying to create or overwrite a file through cURL on another computer (Machine2). So Machine2 is connected to Machine1. Ive been looking through cURL's documentation for command that will do this but have had no luck and as well on stack overflow.

https://curl.haxx.se/docs/manpage.html

I have also tried the examples on this SO post:

HTTP POST and GET using cURL in Linux

Any idea as to what the command might be through command prompt? (equivalent of a POST command). I have tried so far using -O, -K, -C and a multitude of others which have not worked.

Community
  • 1
  • 1
lucyb
  • 333
  • 5
  • 15
  • 3
    So, curl isn't magic. What protocols/APIs are there on the remote server? FTP? SSH? Some kind of WebDAV API? – Joe Mar 24 '17 at 00:06
  • 1
    HTTP get and post...the server is just a python file – lucyb Mar 24 '17 at 00:09
  • 1
    To use GET and POST you need some kind of server process running on the server. Does your python code that is running serve up some kind of API? curl can't just arbitrarily create files; it's just a protocol client on top of other implementations. In the API case, it assumes that there's existing HTTP endpoints that can take the actions that you need (there is no generic HTTP GET/POST for creating files) – Joe Mar 24 '17 at 00:21
  • @lucyb is your question correctly answered? If yes, maybe you can "accept" my answer? – shaochuancs May 03 '17 at 03:14

1 Answers1

3

In command line, all you need to do is using curl --form to simulate a multipart/form-data POST request:

curl --form "testfile=@thefilename.jpg" http://<Machine2>/<Path>

testfile is the field name used for form, if you don't care, just use any english word.

@ is used here to make file thefilename.jpg get attached in the post as a file upload. Refer to curl man doc.

In server side, URL http://<Machine2>/<Path> should be listened. When curl send the previous POST request, server side program should get it, extract the attached file (thefilename.jpg), and save to disk.

shaochuancs
  • 15,342
  • 3
  • 54
  • 62