适用人群:更灵活使用iterm上传和下载
1、首先要有iTerm2
iTerm2官网下载地址:iTerm2下载链接
2、本地安装lrzxz
brew install lrzsz
3、下载iterm2-send-zmodem.sh 和 iterm2-recv-zmodem.sh脚本文件
见附件
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
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz "$FILE" -e -b
sleep 1
echo
echo \# Received $FILE
fi
iterm2-recv-zmodem.sh
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"
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz -E -e -b
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi
4、将这两个脚本文件保存到/usr/local/bin/ 路径下,cd到该目录下为其添加可执行权限。
chmod +x iterm2-send-zmodem.shchmod +x iterm2-recv-zmodem.sh
5、iterm2 添加 triggers
打开“Preferences”面板->Profiles选项卡->Advanced->Triggers(点击Edit即可)
Regular expression: \*\*B0100Action: Run Silent CoprocessParameters: /usr/local/bin/iterm2-send-zmodem.shRegular expression: \*\*B00000000000000Action: Run Silent CoprocessParameters: /usr/local/bin/iterm2-recv-zmodem.sh
见下图
一切就绪就可以愉快地使用了。
再啰嗦一嘴,在远程服务器端也需要事先安装lrzsz。
yum -y install lrzsz
附rz sz命令使用方法
To send a file to a remote machine: Type "rz" on the remote machine Select the file(s) on the local machine to send Wait for the coprocess indicator to disappear
The receive a file from a remote machine
Type "sz filename1 filename2 … filenameN" on the remote machine
Select the folder to receive to on the local machine
Wait for the coprocess indicator to disappear