最近有将本地文件传向服务器的需求,于是从同事那里听来了rz、sz这个黑魔法,迫不及待就安装使用了一下,极其好用。
(PS:不要问为嘛不使用scp,因为种种原因无法使用,而且有了这个之后即使可以使用scp我也不会用了,为嘛?懒!输命令很麻烦!ip记不住更麻烦!)
百度的开发机需要跳两次,所以scp不好使了
安装配置
安装lrzsz
使用 brew install lrzsz 。如果安装遇到错误的话,使用以下方法:
curl -k https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz -o lrzsz-0.12.20.tar.gz
- 1
将下载的文件放到 ~/Library/Caches/Homebrew 目录下
brew install lrzsz
- 1
将 iterm2-send-zmodem.sh 和 iterm2-recv-zmodem.sh 脚本保存在 /usr/local/bin/
#!/bin/bash
# iterm2-recv-zmodem.sh
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)&\"\")"`
if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
echo \# Cancelled transfer
echo
else
echo $FILE
cd "$FILE"
/usr/local/bin/rz
echo \# Received $FILE
echo
fi
- 18
#!/bin/bash
# iterm2-send-zmodem.sh
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)&\"\")"`
if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
echo \# Cancelled transfer
echo
else
echo $FILE
/usr/local/bin/sz "$FILE"
echo \# Received $FILE
echo
fi
- 1
- 217
在iTerm 2添加Triggers
打开iTerm的Preferences,或者使用 command + , ,点进Profiles项,Advanced项,进入Tirggers,点击Edit,添加两条规则:
Regular expression: rz waiting to receive.\*\*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
- 1
- 27
至此,所有配置完成。下面就可以使用黑科技来传输文件了。
使用方法
将文件传到远端服务器
在远端服务器上输入 rz ,回车
选择本地要上传的文件
等待上传
从远端服务器下载文件
在远端服务器输入 sz filename filename1 … filenameN
选择本地的存储目录
等待下载
PS:远端服务器也需要安装lrzsz。
centOS安装方法: yum -y install lrzsz
存在的问题
大文件传输不了,会卡住
2713

被折叠的 条评论
为什么被折叠?



