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

3 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "os"
  8. "path/filepath"
  9. );
  10. func main() {
  11. port := flag.String("p", "8035", "port to serve on")
  12. file := flag.String("file", ".", "file to serve");
  13. flag.Parse();
  14. fi, err := os.Stat(*file);
  15. if (err != nil) {
  16. fmt.Println(err);
  17. return
  18. }
  19. if (!fi.Mode().IsRegular()) {
  20. fmt.Printf("File %s is not a file.", *file);
  21. return
  22. }
  23. *file, _ = filepath.Abs(*file);
  24. log.Printf("Attempting to run getfile at port %s with file %s\n", *port, *file);
  25. //http.Handle("/", http.FileServer(http.Dir(".")));
  26. http.HandleFunc("/", func (res http.ResponseWriter, req *http.Request) {
  27. log.Printf("called");
  28. http.ServeFile(res, req, *file);
  29. });
  30. log.Fatal(http.ListenAndServe(":"+*port, nil));
  31. }