Sometimes I'll be working on a project, and I'll find myself in need to share a single file over http. For instance, I may need to test that a program or script is correctly grabbing files over http with Invoke-WebRequest, or curl. I may need to quickly have a file upload available, and the only reliable way is via an http server (polycom certificates for example)
I don't want to setup IIS, WAMP, or anything permanent, I just need a quick webserver on a single port temporarily.
For this, I will use ncat.
To continue on with the use cases below, head over to https://nmap.org/ncat/ and download nmap. For this example, place the ncat.exe in the Directory you are going to be running the script from, as well as any files you are wishing to serve up.
$mime = "image/jpeg"
.\ncat -lk -p 8080 --sh-exec "echo HTTP/1.1 200 OK\r\nContent-Type: $mime\r\n& echo(&type jpeg-home.jpg"
jpeg-home.jpg is in current working directory.
ncat.exe is in the current working directory
that this is a jpeg file. If it is a gif or png, you will need to adjust the mime type
I've found that this can be done without the mime type. Perhaps this is implied if not specified.
.\ncat -lk -p 8080 --sh-exec "echo HTTP/1.1 200 OK\r\n& echo(&type index.html"
$mime = "application/pkix-cert" .\ncat -lk -p 8080 --sh-exec "echo HTTP/1.1 200 OK\r\nContent-Type: $mime\r\n& echo(&type lyncpool.crt"
Other File Types
You will need to change $mime to match your file type. The list I have used to find the appropriate mime type is available here: https://www.sitepoint.com/web-foundations/mime-types-complete-list/