安装Zmodem的实现
brew install lrzsz
创建脚本
将下面两个脚本创建到/usr/local/bin
目录
iterm2-send-zmodem.sh
#!/bin/bash
# Author: Matt Mastracci ([email protected])
# 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
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
iterm2-recv-zmodem.sh
#!/bin/bash
# Author: Matt Mastracci ([email protected])
# 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
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
设置iTerm2
修改iTerm2的default trigger(iTerm偏好设置-> Profiles -> Default -> Advanced -> Triggers的Edit按钮
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
发送文件到远端服务器
- 在远端服务器执行
rz
- 本地选择文件传输
- 等待传输指示消失
接收远端服务器的文件
- 再远端服务器执行
sz filename1 filename2 … filenameN
- 本地选择目录保存
- 等待传输指示消失