# croc用法实践(电脑或手机间文件、文件夹传输)

croc用法实践(电脑或手机间文件、文件夹传输)


croc 是一种工具,允许任何两台计算机简单安全地传输文件和文件夹。AFAIK, croc 的 CLI 文件传输工具 是唯一执行以下所有 操作,不仅支持一般操作系统,还支持termux

  • 允许 任意两台计算机 传输数据(使用中继)

  • 提供 端到端加密 (使用 PAKE)

  • 实现轻松 的跨平台 传输(Windows、Linux、Mac)

  • 允许 多个文件 传输

  • 允许 恢复 中断的

  • 本地服务器或端口转发 不需要

  • IPv6 优先, 带 IPv4 回退

  • 可以使用 代理 ,如 Tor

项目地址https://github.com/schollz/croc

1 安装

安装请看官方文档https://github.com/schollz/croc

  • 在linux上
curl https://getcroc.schollz.com | bash
  • 在 Termux 上
pkg install croc
  • 在Windows上
scoop install croc
或
choco install croc
或
winget install schollz.croc

2 使用示例

2.1 发送文件

  • 发送端
[root@v-192-168-11-81-deploy:~]# croc send  1.txt
Sending '1.txt' (24 B)           
Code is: 4682-epoxy-bagel-uniform
On the other computer run

croc 4682-epoxy-bagel-uniform        #-- 接收端使用此命令接收
  • 接收端
croc 4682-epoxy-bagel-uniform

发送多个文件:
croc send file1.txt file2.txt file3.txt
或者:
croc send *.jpg

2.2 发送文件夹

  • 发送端
[root@v-192-168-11-81-deploy:~]# croc send  nginx-probe/
Sending 3 files and 2 folders (1.3 kB)
Code is: 3033-catalog-penguin-amanda
On the other computer run

croc 3033-catalog-penguin-amanda
  • 接收端
[root@mtss-www-10-2-3-161 ~]# croc 3033-catalog-penguin-amanda
Accept 3 files and 2 folders (1.3 kB)? (Y/n) Y

Receiving (<-116.24.75.125:55253)
nginx-probe/
 Dockerfile            100% |████████████████████| (164/164 B, 352 B/s) 1/3
 probe.conf            100% |████████████████████| (590/590 B, 1.2 kB/s) 2/3
nginx-probe/templates/
 default.conf.template 100% |████████████████████| (584/584 B, 1.2 kB/s) 3/3
[root@mtss-www-10-2-3-161 ~]# ll
总用量 1116
drwxr-xr-x 3 root root     4096 531 15:16 nginx-probe

2.3 发送文本字符串

  • 发送端
[root@v-192-168-11-81-deploy:~]# croc send --text 'abcdefggg'
Sending 'text' (9 B)             
Code is: 0310-miller-fashion-ibiza
On the other computer run

croc --relay 192.168.2.7 0310-miller-fashion-ibiza
  • 接收端
[root@192-168-11-140 ~]# croc --relay 192.168.2.7 0310-miller-fashion-ibiza
Display text message (9 B)? (Y/n) Y

Receiving (<-192.168.11.81:9009)
abcdefggg

2.4 发送时指定code,接收时自动【Y】,并保存到指定目录

  • 发送端
[root@v-192-168-11-81-deploy:~]# croc send  --code  11223344  1.txt
Sending '1.txt' (24 B)           
Code is: 11223344
On the other computer run

croc 11223344
  • 接收端
[root@mtss-www-10-2-3-161 ~]# croc  --yes  --out ./zjlh/  11223344
Receiving '1.txt' (24 B) 

Receiving (<-116.24.75.125:13532)
1.txt 100% |████████████████████| (24/24 B, 52 B/s)
[root@mtss-www-10-2-3-161 ~]# 
[root@mtss-www-10-2-3-161 ~]# ll ./zjlh/
总用量 16
-rw-r--r-- 1 root root   24 531 15:27 1.txt

2.5 使用变量方式发送文件

CROC_RELAY : 指定中继服务器,默认:“5.161.69.143:9009”
CROC_PASS : 指定code,默认随机自动生成
CROC_RELAY6 : 指定中继服务器ipv6,默认:“[2a01:4ff:f0:23c2::14c:1]:9009”
SOCKS5_PROXY : 使用socks5代理

  • 发送端
[root@v-192-168-11-81-deploy:~]# export  CROC_PASS='11223344'
[root@v-192-168-11-81-deploy:~]# croc send  1.txt
Sending '1.txt' (24 B)           
Code is: 11223344
On the other computer run

croc 11223344
  • 接收端
[root@mtss-www-10-2-3-161 ~]# croc  --yes  11223344
Receiving '1.txt' (24 B) 

Receiving (<-116.24.75.125:13532)
1.txt 100% |████████████████████| (24/24 B, 52 B/s)

2.6 使用自建中继服务器

默认情况下, croc 使用公共中继,但您也可以运行自己的中继服务器。中继服务器默认使用 TCP 端口 9009-9013。确保打开他。也可以自定义端口(例如 croc relay --ports 1111,1112),但中继必须至少有 2 个端口。第一个端口用于通信,后续端口用于多路复用数据传输。

  • 1 开启中继服务器
kevin@TM1701-b38cbc23:~$ croc relay
[info]	2023/05/31 15:33:41 starting croc relay version v9.6.4-1fce28e
[info]	2023/05/31 15:33:41 starting TCP server on :9009
[info]	2023/05/31 15:33:41 starting TCP server on :9011
[info]	2023/05/31 15:33:41 starting TCP server on :9013
[info]	2023/05/31 15:33:41 starting TCP server on :9012
[info]	2023/05/31 15:33:41 starting TCP server on :9010
  • 2 发送
[root@v-192-168-11-81-deploy:~]# croc  --relay 192.168.2.7  send  1.txt
Sending '1.txt' (24 B)           
Code is: 2366-happy-object-virgo
On the other computer run

croc --relay 192.168.2.7 2366-happy-object-virgo
  • 3 接收
[root@192-168-11-140 ~]# croc --relay 192.168.2.7 2366-happy-object-virgo
Accept '1.txt' (24 B)? (Y/n) Y

Receiving (<-127.0.0.1:36274)
1.txt 100% |████████████████████| (24/24 B, 3.0 kB/s)

3 帮助

3.1 croc help

[root@t-trav-deploy-10-1-213-24 ~]# croc help   #-- 我翻译简化了

用法:
    croc  [命令参数]  [全局选项]

命令:
   send     发送文件或文件夹
   relay    运行自己的中级服务器(可选,默认使用官方)
   help, h  帮助

全局选项:
   --yes                   自动同意 (default: false)
   --overwrite             覆盖不提示 (默认: false)
   --relay value           指定ipv4中继服务器 (默认: "5.161.69.143:9009") [$CROC_RELAY]
   --pass value            中继服务器密码 (默认: "pass123") [$CROC_PASS]
   --socks5 value          使用socks5代理 [$SOCKS5_PROXY]
   --out value             指定接收文件位置 (默认: ".")

3.2 croc relay help

[root@t-trav-deploy-10-1-213-24 ~]# croc relay --help
用法:
   croc relay [command options] [arguments...]

描述:
   start relay

选项:
   --host value   指定中继主机名称(没啥用)
   --ports value  指定中继服务器端口 (默认: "9009,9010,9011,9012,9013")
   --help, -h     show help (default: false)

3.3 croc send help

[root@t-trav-deploy-10-1-213-24 ~]# croc send --help
用法:
   croc send [command options] [filename(s) or folder]

描述:
   send file(s), or folder, over the relay

选项:
   --zip                   发送前先压缩 (default: false)
   --code value, -c value  指定code(接收时用的code)
   --text value, -t value  指定发送文本
   --ports value           指定自建中继服务器端口(可选) (默认: "9009,9010,9011,9012,9013")
   --help, -h              show help (default: false)

4 最后

img

爱你!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值