Skip to content

Instantly share code, notes, and snippets.

@abhaikollara abhaikollara/
Last active Dec 2, 2018

What would you like to do?


A simple command line file sharing tool


goSend -f ~/pathToFile/theFile

Anyone in the local network can go to the host address (default: to receive the file.


  • -f The path to file
  • -h host ip address
  • -p port
  • -download If set to false, the browser will try to display the file
package main
import (
func main() {
filePath := flag.String("f", "", "path to file")
host := flag.String("h", "", "host")
port := flag.String("p", "8000", "port")
download := flag.Bool("download", true, "if set to False the browser will display the file if possible")
if *filePath == "" {
fmt.Println("Usage: goSend -f path_to_file")
// fmt.Println(net.LookupHost("en0"))
http.HandleFunc("/", baseHandler(filePath, download))
fmt.Printf("Serving on http://%v:%v\n", *host, *port)
log.Fatal(http.ListenAndServe(*host+":"+*port, nil))
func baseHandler(filePath *string, download *bool) func(http.ResponseWriter, *http.Request) {
fileName := filepath.Base(*filePath)
contentDisposition := "attachment"
if *download == false {
contentDisposition = "inline"
contDispos := fmt.Sprintf("%v;filename=%v", contentDisposition, url.QueryEscape(fileName))
return func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
w.Header().Set("Content-Disposition", contDispos)
http.ServeFile(w, r, *filePath)
fmt.Printf("Served %v to %v\n", fileName, r.RemoteAddr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.