mac/win安装lrzsz(文件传输神器)

277 阅读1分钟

mac

安装 iterm2

注意: 文件传输需要在 iterm2 中进行

安装 homebrew

终端输入指令.亲测可用,无需翻墙

/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

查看版本确定安装成功 brew -v

image.png

安装 lrzsz

终端输入指令

brew install lrzsz

安装结束之后可输入 brew list 确定是否安装成功

image.png

iterm2 配置

准备工作

  1. iterm2 进入 /usr/local/bin 文件下
cd /usr/local/bin
  1. 新建 iterm2-recv-zmodem.sh 文件,并输入以下内容:
#!/bin/bash

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
	FILE=$(osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
else
	FILE=$(osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
fi

if [[ $FILE = "" ]]; then
	echo Cancelled.
	# Send ZModem cancel
	echo -e \\x18\\x18\\x18\\x18\\x18
	sleep 1
	echo
	echo \# Cancelled transfer
else
	cd "$FILE"
	/usr/local/bin/rz -E -e -b --bufsize 4096
	sleep 1
	echo
	echo
	echo \# Sent \-\> $FILE
fi
  1. 新建 iterm2-send-zmodem.sh 文件, 并输入一下内容:
#!/bin/bash


osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
	FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
	FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi
if [[ $FILE = "" ]]; then
	echo Cancelled.
	# Send ZModem cancel
	echo -e \\x18\\x18\\x18\\x18\\x18
	sleep 1
	echo
	echo \# Cancelled transfer
else
	/usr/local/bin/sz "$FILE" --escape --binary --bufsize 4096
	sleep 1
	echo
	echo \# Received $FILE
fi
  1. 开通一下文件权限
sudo chmod +x iterm2-*

配置 iterm2

左上角点击 iterm2 -> preference -> profiles -> default -> advanced -> triggers 栏的 edit
动图可放心食用(配置后的 triggers),正常来说打开编辑页应该是空的

2022-01-19 10.34.52.gif

新增两个配置,配置信息分别如下:

Regular expression: \*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh

Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh

放一张配置好的图

image.png

配置完成!

如何使用

  • 使用 iterm2 登录需要传输文件的服务器
  • 在需要上传的目录输入 rz
  • 选中目标文件

win

win 的使用需要在 xshell 工具下进行

安装 xshell

在目标服务器上安装 lrzsz

yum install -y lrzsz

使用 xshell 登录目标服务器

  • 目标文件夹输入 rz 上传文件