背景
之前一直在Ubuntu下开发,经常会在服务器和本地来回拷贝文件,一直使用scp命令,这会儿切换到Mac之后,发现scp在局域网下好使,但是不在一个局域网下就不好使了,OMG,不能上传下载文件,总感觉缺点啥,索性上网查查有啥解决办法,看了很多也实际操作了,发现iTerm2能完美解决这个问题,所以留个笔记记录记录< - …- >
1、下载iTerm2
iTerm2下载地址:https://www.iterm2.com/downloads.html
2、下载iterm2-zmodem脚本
地址: https://github.com/mmastrac/iterm2-zmodem
然后将iterm2-send-zmodem.sh & iterm2-recv-zmodem.sh放到/usr/local/bin/
下载链接失效,可以直接新建.sh
term2-send-zmodem.sh
#!/bin/bash
#这个脚本来自 github,删掉了一些 ** 言论。
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" -e -b
sleep 1
echo
echo \# Received $FILE
fi
iterm2-recv-zmodem.sh
#!/bin/bash
#这个脚本来自 github,删掉了一些 ** 言论。
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
添加可执行权限chmod 7777 iterm2-*
3、安装lrzsz
命令: brew install lrzsz
4、配置iTerm2的triggers
a.选择profiles
b.Edit Default
c.选择advanced+Triggers Edit
d.添加Triggers
triggers配置如下(网上这个配置的版本很多,亲测这个配置是好使的):
Regular expression: rz waiting to receive.\*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh
Instant: checked
Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
Instant: checked
5、测试
测试了一下sz/rz命令很好使,很好,perfect…