schollz / croc

schollz / croc

This project’s future depends on community support. Become a sponsor today. 该项目的未来取决于社区的支持。欢迎立即成为赞助者。

About croc is a tool that allows any two computers to simply and securely transfer files and folders. AFAIK, croc is the only CLI file-transfer tool that does all of the following: 关于 croc:croc 是一款允许任意两台计算机简单且安全地传输文件和文件夹的工具。据我所知,croc 是唯一具备以下所有功能的命令行(CLI)文件传输工具:

  • Allows any two computers to transfer data (using a relay)
  • 提供任意两台计算机之间的数据传输(使用中继服务器)
  • Provides end-to-end encryption (using PAKE)
  • 提供端到端加密(使用 PAKE 协议)
  • Enables easy cross-platform transfers (Windows, Linux, Mac)
  • 支持跨平台轻松传输(Windows、Linux、Mac)
  • Allows multiple file transfers
  • 支持多文件传输
  • Allows resuming transfers that are interrupted
  • 支持断点续传
  • No need for local server or port-forwarding
  • 无需本地服务器或端口转发
  • IPv6-first with IPv4 fallback
  • 优先使用 IPv6,并支持 IPv4 回退
  • Can use a proxy, like Tor
  • 支持使用代理(如 Tor)

For more information about croc, see my blog post or read a recent interview I did. 欲了解更多关于 croc 的信息,请查看我的博客文章或阅读我最近接受的采访。

Install / 安装

You can download the latest release for your system, or install a release from the command-line: 你可以为你的系统下载最新版本,或通过命令行安装:

curl https://getcroc.schollz.com | bash

On macOS 在 macOS 上

Using Homebrew: brew install croc 使用 Homebrew:brew install croc

Using MacPorts: sudo port selfupdate then sudo port install croc 使用 MacPorts:sudo port selfupdate 然后 sudo port install croc

On Windows 在 Windows 上

You can install the latest release with Scoop, Chocolatey, or Winget: 你可以使用 Scoop、Chocolatey 或 Winget 安装最新版本:

scoop install croc choco install croc winget install schollz.croc

Using nix-env 使用 nix-env

You can install the latest release with Nix: nix-env -i croc 你可以使用 Nix 安装最新版本:nix-env -i croc

On NixOS 在 NixOS 上

You can add this to your configuration.nix: environment.systemPackages = [ pkgs.croc ]; 你可以将其添加到你的 configuration.nix 中:environment.systemPackages = [ pkgs.croc ];

On Alpine Linux 在 Alpine Linux 上

First, install dependencies: apk add bash coreutils then wget -qO- https://getcroc.schollz.com | bash 首先安装依赖:apk add bash coreutils 然后 wget -qO- https://getcroc.schollz.com | bash

On Arch Linux 在 Arch Linux 上

Install with pacman: pacman -S croc 使用 pacman 安装:pacman -S croc

On Fedora 在 Fedora 上

Install with dnf: dnf install croc 使用 dnf 安装:dnf install croc

On Gentoo 在 Gentoo 上

Install with portage: emerge net-misc/croc 使用 portage 安装:emerge net-misc/croc

On Termux 在 Termux 上

Install with pkg: pkg install croc 使用 pkg 安装:pkg install croc

On FreeBSD 在 FreeBSD 上

Install with pkg: pkg install croc 使用 pkg 安装:pkg install croc

On Linux, macOS, and Windows via Conda 通过 Conda 在 Linux、macOS 和 Windows 上

You can install from conda-forge globally with pixi: pixi global install croc 你可以使用 pixi 从 conda-forge 全局安装:pixi global install croc

Or install into a particular environment with conda: conda install --channel conda-forge croc 或者使用 conda 安装到特定环境:conda install --channel conda-forge croc

On Linux, macOS via Docker 通过 Docker 在 Linux、macOS 上

Add the following one-liner function to your ~/.profile (works with any POSIX-compliant shell): 将以下单行函数添加到你的 ~/.profile 中(适用于任何符合 POSIX 标准的 shell):

croc() { [ $# -eq 0 ] && set -- ""; mkdir -p "$HOME/.config/croc"; docker run --rm -it --user "$(id -u):$(id -g)" -v "$(pwd):/c" -v "$HOME/.config/croc:/.config/croc" -w /c -e CROC_SECRET docker.io/schollz/croc "$@"; }

You can also just paste it in the terminal for current session. On first run Docker will pull the image. croc via Docker will only work within the current directory and its subdirectories. 你也可以直接将其粘贴到终端以在当前会话中使用。首次运行时 Docker 会拉取镜像。通过 Docker 运行的 croc 仅在当前目录及其子目录内有效。

Build from Source 从源码构建

If you prefer, you can install Go and build from source (requires Go 1.22+): 如果你愿意,可以安装 Go 并从源码构建(需要 Go 1.22+):

go install github.com/schollz/croc/v10@latest

On Android 在 Android 上

There are two F-Droid apps available: 有两个 F-Droid 应用可用:

  • crocgui — original port (Go, basic UI)
  • crocgui — 原始移植版(Go 语言,基础 UI)
  • croc-app — native Kotlin/Jetpack Compose client with a modern, mobile-first interface
  • croc-app — 原生 Kotlin/Jetpack Compose 客户端,具有现代化的移动优先界面

Usage / 使用方法

To send a file, simply do: 发送文件只需执行:

$ croc send [file(s)-or-folder] Sending 'file-or-folder' (X MB) Code is: code-phrase

Then, to receive the file (or folder) on another computer, run: 然后在另一台计算机上接收文件(或文件夹),运行:

croc code-phrase

The code phrase is used to establish password-authenticated key agreement (PAKE) which generates a secret key for the sender and recipient to use for end-to-end encryption. 代码短语用于建立密码认证密钥交换(PAKE),它会生成一个密钥,供发送方和接收方进行端到端加密使用。

Customizations & Options / 自定义与选项

Using croc on Linux or macOS 在 Linux 或 macOS 上使用 croc

On Linux and macOS, the sending and receiving process is slightly different to avoid leaking the secret via the process name. You will need to run croc with the secret as an environment variable. For example, to receive with the secret ***: 在 Linux 和 macOS 上,发送和接收过程略有不同,以避免通过进程名称泄露密钥。你需要将密钥作为环境变量来运行 croc。例如,使用密钥 *** 接收:

CROC_SECRET=*** croc

For single-user systems, the default behavior can be permanently enabled by running: croc --classic 对于单用户系统,可以通过运行 croc --classic 来永久启用默认行为。

Custom Code Phrase 自定义代码短语

You can send with your own code phrase (must be at least 6 characters): 你可以使用自己的代码短语发送(必须至少 6 个字符):

croc send --code [code-phrase] [file(s)-or-folder]

Allow Overwriting Without Prompt 允许自动覆盖而不提示

To automatically overwrite files without prompting, use the —overwrite flag: 要自动覆盖文件而不提示,请使用 --overwrite 标志:

croc --yes --overwrite <code>

Excluding Folders 排除文件夹

To exclude folders from being sent, use the —exclude flag with comma-delimited exclusions: 要排除发送某些文件夹,请使用 --exclude 标志并用逗号分隔排除项:

croc send --exclude "node_modules,.venv" [folder]

Use Pipes - stdin and stdout 使用管道 - 标准输入和标准输出

You can pipe to croc: cat [filename] | croc send 你可以通过管道传输给 croc:cat [filename] | croc send

To receive the file to stdout, you can use: croc --yes [code-phrase] > out 要将文件接收到标准输出,可以使用:croc --yes [code-phrase] > out

Send Text 发送文本

To send URLs or short text, use: croc send --text "hello world" 要发送 URL 或短文本,请使用:croc send --text "hello world"

Send Multiple Files 发送多个文件

You can send multiple files directly by listing the files and/or folders: 你可以通过直接列出文件和/或文件夹来发送多个文件:

croc send [file1] [file2] [file3] [folder1] [folder2]

Show QR Code 显示二维码

To show QR code (for mobile devices), use: croc send --qr [file(s)-or-folder] 要显示二维码(用于移动设备),请使用:croc send --qr [file(s)-or-folder]

Use a Proxy 使用代理

You can send files via a proxy by adding —socks5: 你可以通过添加 --socks5 来通过代理发送文件:

croc --socks5 "127.0.0.1:9050" send SOMEFILE

Change Encryption Curve 更改加密曲线

To choose a different elliptic curve for encryption, use the —curve flag: 要为加密选择不同的椭圆曲线,请使用 --curve 标志:

croc --curve p521 <codephrase>

Change Hash Algorithm 更改哈希算法

For faster hashing, use the imohash algorithm: 为了更快的哈希计算,请使用 imohash 算法:

croc send --hash imohash SOMEFILE

Clipboard Options 剪贴板选项

By default, the code phrase is copied to your clipboard. To disable this: 默认情况下,代码短语会被复制到你的剪贴板。要禁用此功能:

croc --disable-clipboard send [filename]

To copy the full command with the secret as an environment variable (useful on Linux/macOS): 要将包含密钥作为环境变量的完整命令复制到剪贴板(在 Linux/macOS 上很有用):

croc --extended-clipboard send [filename]

This copies the full command like CROC_SECRET="code-phrase" croc (including any relay/pass flags). 这会复制完整的命令,例如 CROC_SECRET="code-phrase" croc(包括任何中继/密码标志)。

Quiet Mode 静默模式

To suppress all output (useful for scripts and automation): 要抑制所有输出(适用于脚本和自动化):

croc --quiet send [filename]

Self-host Relay 自托管中继服务器

You can run your own relay: croc relay 你可以运行自己的中继服务器:croc relay

By default, it uses TCP ports 9009-9013. You can customize the ports (e.g., croc relay --ports 1111,1112), but at least 2 ports are required. 默认情况下,它使用 TCP 端口 9009-9013。你可以自定义端口(例如 croc relay --ports 1111,1112),但至少需要 2 个端口。

To send files using your relay: 使用你的中继服务器发送文件:

croc --relay "myrelay.example.com:9009" send [filename]

Self-host Relay with Docker 使用 Docker 自托管中继服务器

You can also run a relay with Docker: 你也可以使用 Docker 运行中继服务器:

docker run -d -p 9009-9013:9009-9013 -e CROC_PASS='YOURPASSWORD' docker.io/schollz/croc

To send files using your custom relay: 使用你的自定义中继服务器发送文件:

croc --pass YOURPASSWORD --relay "myreal.example.com:9009" send [filename]

To use custom ports, set CROC_PORTS (comma-separated) or CROC_PORT (base port): 要使用自定义端口,请设置 CROC_PORTS(逗号分隔)或 CROC_PORT(基础端口):

docker run -d -p 9010-9011:9010-9011 -e CROC_PORTS='9010,9011' -e CROC_PASS='YOURPASSWORD' docker.io/schollz/croc

Acknowledgements 致谢

croc has evolved through many iterations, and I am thankful for the contributions. croc 经历了多次迭代,我非常感谢所有的贡献。