macos下iTerm2使用rz、sz命令传输文件,解决通过堡垒机登陆后无法传输文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了macos下iTerm2使用rz、sz命令传输文件,解决通过堡垒机登陆后无法传输文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3563字,纯文字阅读大概需要6分钟。
内容图文
![macos下iTerm2使用rz、sz命令传输文件,解决通过堡垒机登陆后无法传输文件](/upload/InfoBanner/zyjiaocheng/1021/5e30ee5933ec4e2681a1d17107e8cc38.jpg)
说明:使用rz sz实现终端的文件传输,该命令主要使用场景为 macos中通过堡垒机登陆后无法使用ftp工具传输文件。
工具:iTerm2、lrzsz、homebrew
以及两个脚本文件(iterm2-recv-zmodem.sh、iterm2-send-zmodem.sh)
- iTerm2
下载完直接拖进应用程序就可以了
- 安装homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- lrzsz
brew install lrzsz
配置rz sz 进行上传下载
cd /usr/local/bin
在该目录下创建脚本
脚本内容如下:
1. 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
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
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi
2. 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
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
保存好后添加执行权限
sudo chmod u+x iterm2-*
iTerm2 配置添加rz sz 功能
Perference-> Profiles -> Default -> Advanced -> Triggers 的 Edit 按钮
或者使用快捷键command+,
编辑内容如下:
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
配置完成后如果还无法正常使用,遇到下面的错误,需要建立rz、sz软连接到/usr/local/bin 下即可
操作步骤如下:
1.找到文件位置
2.建立软连接
检查软连接是否创建
这两个命令就可以正常使用了
rz 上传功能
- 在bash中,也就是iTerm2终端输入rz 就会弹出文件选择框,选择文件 choose 就开始上传,会上传到当前目录
sz 下载功能
- sz fileName(你要下载的文件的名字) 回车
- 会弹出窗体 我们选择要保存的地方即可。
内容总结
以上是互联网集市为您收集整理的macos下iTerm2使用rz、sz命令传输文件,解决通过堡垒机登陆后无法传输文件全部内容,希望文章能够帮你解决macos下iTerm2使用rz、sz命令传输文件,解决通过堡垒机登陆后无法传输文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。