通常而言我们可能一般是使用scp命令来进行文件的下载和上传,对于习惯了window中使用xShell的用户可能更喜欢rz和sz的操作,Mac中在安装iTerm之后也能进行rz和sz的安装使用。
第一种方式
使用scp命令的形式,在两台主机之间使用scp进行上传和下载
scp -r username@ip:folder username@ip:folder
然后按照提示输入两台主机的密码
第二种方式
使用rz和sz的方式进行,在安装完成iTerm2之后打开,然后使用homebrew的方式安装lrzsz
1、安装 lrzsz
zh ~ % brew install lrzsz
==> Downloading https://homebrew.bintray.com/bottles/lrzsz-0.12.20_1.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring lrzsz-0.12.20_1.catalina.bottle.tar.gz
🍺 /usr/local/Cellar/lrzsz/0.12.20_1: 18 files, 473.9KB
zh ~
2、新建 iterm2-recv-zmodem.sh、iterm2-send-zmodem.sh 文件
注意是在 mac 上新建
zh bin % vi iterm2-recv-zmodem.sh
zh bin %
zh bin % vi iterm2-send-zmodem.sh
内容从 https://github.com/snow-sprite/rzsz GitHub 上复制
iterm2-recv-zmodem.sh内容如下:
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
#COMMAND=$(which rz)
if [[ -f /opt/homebrew/bin/rz ]]; then
COMMAND=/opt/homebrew/bin/rz
else
COMMAND=/usr/local/bin/rz
fi
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"
$COMMAND --rename --escape --binary --bufsize 4096
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi
iterm2-send-zmodem.sh内容如下:
###
# @Author: your name
# @Date: 2019-12-11 01:03:06
# @LastEditTime: 2019-12-11 01:03:21
# @LastEditors: your name
# @Description: In User Settings Edit
# @FilePath: /rzsz/iterm2-send-zmodem.sh
###
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
#COMMAND=$(which sz)
if [[ -f /opt/homebrew/bin/sz ]]; then
COMMAND=/opt/homebrew/bin/sz
else
COMMAND=/usr/local/bin/sz
fi
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
$COMMAND "$FILE" --escape --binary --bufsize 4096
sleep 1
echo
echo \# Received "$FILE"
fi
3、设置文件权限
chmod a+x /usr/local/bin/iterm2-recv-zmodem.sh /usr/local/bin/iterm2-send-zmodem.sh
4、配置 iterm2
打开iTerm2的Preferences(快捷键command+,),然后Profiles->Default->Advanced->Triggers->Edit进入到编辑界面。
在Triggers界面点击左下角的加号按钮新建两行,Regular Expression分别为rz waiting to receive.\*\*B0100和\*\*B00000000000000,Action都选择Run Silent Coprocess...,Parameters分别为/usr/local/bin/iterm2-send-zmodem.sh和/usr/local/bin/iterm2-recv-zmodem.sh
5、测试验证
在iTerm2上输入rz,会自动弹出访问来,然后选择要上传的文件即可。
sz下载。