在iTerm2中使用Zmodem传输文件

安装Zmodem的实现

brew install lrzsz

创建脚本

将下面两个脚本创建到/usr/local/bin目录

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
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 (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
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

发送文件到远端服务器

  1. 在远端服务器执行rz
  2. 本地选择文件传输
  3. 等待传输指示消失

接收远端服务器的文件

  1. 再远端服务器执行sz filename1 filename2 … filenameN
  2. 本地选择目录保存
  3. 等待传输指示消失
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值