用 Go 寫的文件傳輸工具 croc 瞭解一下
我是一隻可愛的土撥鼠,專注於分享 Go 職場、招聘和求職,解 Gopher 之憂!歡迎關注我。
土撥鼠最近換了 M1 的電腦,由於 MAC 的隔空發送一直髮現不了對方,就想起 17 年用過的一個用 Go 寫的傳輸工具,一直有點印象,忘記叫什麼名了,在 GitHub 上 star 列表終於才搜到 croc[1]。這下趕緊順手給他歸了一下 repo 的類別。
下來土撥鼠簡單介紹一下這個庫。croc
有鱷魚的意思,so 這裏就用鱷魚的圖代表了庫。
croc
是一種允許任何兩臺計算機簡單安全地傳輸文件和文件夾的工具。據我所知,croc
是唯一可以執行以下所有操作的 CLI 文件傳輸工具:
-
允許任何兩臺計算機傳輸數據(使用中繼服務器)
-
提供端到端加密(使用 PAKE)
-
實現輕鬆的跨平臺傳輸(Windows、Linux、Mac)
-
允許多個文件傳輸
-
允許恢復被中斷的傳輸
-
不需要本地服務器或端口轉發
-
ipv6-first 和 ipv4 後備
-
可以使用代理,比如 tor
有關詳細信息croc
,請參閱博客文章 [2]。
安裝
mac 下可以直接使用 brew 進行安裝。
brew install croc
若你使用其他平臺和方式的話,也可以根據 go get 和 go install 進行安裝。
使用
自定義 Code 傳輸文件
這裏我試驗了傳輸文件的例子。
# send
croc send --code code-phrase [file(s)-or-folder]
# receive
croc code-phrase
-
send
: 表示發送 -
--code:指定傳輸和接收的 code(不小於 6 個字符),用於建立密碼驗證密鑰協議 ( PAKE[3] ),也可以不帶此選項會自動生成 code。
croc 發送
$croc send --code 123456 zshrc
Sending 'zshrc' (3.9 kB)
Code is: 123456
On the other computer run
croc 123456
Sending (->192.168.0.103:62532)
100% |████████████████████| (3.9/3.9 kB, 1.711 MB/s)
croc 接收
$ croc 123456
Accept 'zshrc' (3.9 kB)? (Y/n) y
Receiving (<-192.168.0.104:9009)
100% |████████████████████| (3.9/3.9 kB, 213.064 kB/s)
其他例子
使用管道傳輸
cat [filename] | croc send
傳輸文本
croc send --text "hello world"
使用自建中繼服務器
默認情況下,croc
使用公共中繼器。如果你可以不想使用公共的中繼服務器,,你可以搭建自己的中繼服務器,端口你可以自定義,但必須至少有兩個端口。第一個端口用於通信,後續端口用於多路數據傳輸。
docker run -d -p 9009-9013:9009-9013 -e CROC_PASS='croc_relay_1234' schollz/croc
發送文件
$croc --pass croc_relay_1234 --relay "192.168.0.103:9009" send test.md
Sending 'test.md' (13 B)
Code is: 0484-memo-capital-papa
On the other computer run
croc --relay 192.168.0.103:9009 --pass croc_relay_1234 0484-memo-capital-papa
Sending (->192.168.0.103:49170)
100% |████████████████████| (13/13 B, 37.528 kB/s)
接收文件
$croc --relay 192.168.0.103:9009 --pass croc_relay_1234 0484-memo-capital-papa
Accept 'test.md' (13 B)? (Y/n) y
Receiving (<-127.0.0.1:65528)
100% |████████████████████| (13/13 B, 9.311 kB/s)
小結
今天關於 croc 這個小工具的介紹就到這裏了。另外還有一些不錯的基於服務器的文件共享工具:https://send-anywhere.com[4]、https://ipfs.io/ [5]。感興趣的同學也可以看一下。
如果你有更好的庫推薦,歡迎留言討論。
參考資料
[1]
croc: https://github.com/schollz/croc
[2]
博客文章: https://schollz.com/software/croc6
[3]
PAKE: https://en.wikipedia.org/wiki/Password-authenticated_key_agreement
[4]
https://send-anywhere.com: https://send-anywhere.com/
[5]
https://ipfs.io/ : https://ipfs.io/
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源:https://mp.weixin.qq.com/s/LliaEz8JY5PS4gDI2Fq4Qw