dead simple file sharing thru a local network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
774 B

package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
);
func main() {
port := flag.String("p", "8035", "port to serve on")
file := flag.String("file", ".", "file to serve");
flag.Parse();
fi, err := os.Stat(*file);
if (err != nil) {
fmt.Println(err);
return
}
if (!fi.Mode().IsRegular()) {
fmt.Printf("File %s is not a file.", *file);
return
}
*file, _ = filepath.Abs(*file);
log.Printf("Attempting to run getfile at port %s with file %s\n", *port, *file);
//http.Handle("/", http.FileServer(http.Dir(".")));
http.HandleFunc("/", func (res http.ResponseWriter, req *http.Request) {
log.Printf("called");
http.ServeFile(res, req, *file);
});
log.Fatal(http.ListenAndServe(":"+*port, nil));
}