Linux和iPhone互傳文件

當你用Linux工作學習的時,需要在電腦和手機間相互傳送文件,這個時候你會發現沒有一個像airdrop那樣的快捷傳輸方式,動手能力強或者愛折騰的,可以搭建samba,NFS,FTP,NAS等服務來處理,但是感覺有點重,殺雞用牛刀。下面介紹的這個命令行軟件,個人覺得輕量又好用,走的http協議,只要有瀏覽器的設備都可以使用

安裝軟件

  • 沒有golang環境的先安裝golang,比如ubuntu系統

      sudo apt install golang
    
  • 安裝

      go install github.com/codeskyblue/gohttpserver@latest     
    
  • 默認安裝地址

      ➜  ~ go env | grep -i path
      GOPATH="/home/mephisto/go"
      ➜  ~ ls -al /home/mephisto/go/bin 
      total 10223
      drwxrwxr-x 2 mephisto mephisto        3 May 27 13:42 .
      drwxrwxr-x 4 mephisto mephisto        4 May 27 13:42 ..
      -rwxrwxr-x 1 mephisto mephisto 15626232 May 27 13:42 gohttpserver
      ➜  ~ 
    
  • 爲方便使用,也可以放到系統環境變量PATH中

      sudo ln -s /home/mephisto/go/bin/gohttpserver /usr/bin/gohttpserver
    

簡單使用

  • 監聽8000端口,開啓上傳功能, 如下所示,選擇的交換目錄爲/home/mephisto/Pictures/iPhone

      ➜  pwd
      /home/mephisto/Pictures/iPhone
      ➜  gohttpserver -r ./ --port 8000 --upload                            
      2022/05/27 14:08:04 httpstaticserver.go:75: root path: ./
      2022/05/27 14:08:04 main.go:185: plistproxy: "https://plistproxy.herokuapp.com/plist"
      2022/05/27 14:08:04 main.go:244: listening on ":8000", local address http://192.168.199.230:8000
      2022/05/27 14:08:05 httpstaticserver.go:90: Started making search index
      2022/05/27 14:08:05 httpstaticserver.go:92: Completed search index in 167.371µs
    

電腦瀏覽器打開 http://192.168.199.230:8000, 上面輸出日誌中有提示這個地址

  • 手機掃碼訪問,按圖操作上傳或者下載

  • 圖示

    gohttpserver

更多功能請查看幫助

➜  ~ gohttpserver --help
usage: gohttpserver [<flags>]

Flags:
-h, --help                     Show context-sensitive help (also try --help-long and --help-man).
    --version                  Show application version.
    --conf=CONF                config file path, yaml format
-r, --root=ROOT                root directory, default ./
    --prefix=PREFIX            url prefix, eg /foo
    --port=PORT                listen port, default 8000
-a, --addr=ADDR                listen address, eg 127.0.0.1:8000
    --cert=CERT                tls cert.pem path
    --key=KEY                  tls key.pem path
    --auth-type=AUTH-TYPE      Auth type <http|openid>
    --auth-http=AUTH-HTTP      HTTP basic auth (ex: user:pass)
    --auth-openid=AUTH-OPENID  OpenID auth identity url
    --theme=THEME              web theme, one of <black|green>
    --upload                   enable upload support
    --delete                   enable delete support
    --xheaders                 used when behide nginx
    --cors                     enable cross-site HTTP request
    --debug                    enable debug mode
-p, --plistproxy=PLISTPROXY    plist proxy when server is not https
    --title=TITLE              server title
    --google-tracker-id=GOOGLE-TRACKER-ID  
                                set to empty to disable it

最後,這個軟件理論上,只要能跑起來,可以用在任何支持http協議的設備間使用,不限於linux和iPhone

最後修改於: Monday, August 28, 2023

相關文章:

翻譯: