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, 上面输出日志中有提示这个地址
-
手机扫码访问,按图操作上传或者下载
-
图示
更多功能请查看源码地址 https://github.com/codeskyblue/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