Mac上的iTerm2怎么上传和下载⽂件
通常⽽⾔我们可能⼀般是使⽤scp命令来进⾏⽂件的下载和上传,对于习惯了window中使⽤xShell的⽤户可能更喜欢rz和sz的操作,Mac 中在安装iTerm之后也能进⾏rz和sz的安装使⽤。
第⼀种⽅式
使⽤scp命令的形式,在两台主机之间使⽤scp进⾏上传和下载
scp -r username@ip:folder username@ip:folder
然后按照提⽰输⼊两台主机的密码
第⼆种⽅式
使⽤rz和sz的⽅式进⾏,在安装完成iTerm2之后打开,然后使⽤homebrew的⽅式安装lrzsz
1、安装 lrzsz
zh ~ % brew install lrzsz
==> Downloading homebrew.bintray/bottles/lrzsz-0.12.20_1.catalina.
>>>>>>>>>>>>>>## 100.0%
==> Pouring lrzsz-0.12.20_1.catalina.
/usr/local/Cellar/lrzsz/0.12.20_1: 18 files, 473.9KB
zh ~
2、新建 iterm2-recv-zmodem.sh、iterm2-send-zmodem.sh ⽂件
注意是在 mac 上新建
zh bin % vi iterm2-recv-zmodem.sh
zh bin %
zh bin % vi iterm2-send-zmodem.sh
iterm2-recv-zmodem.sh内容如下:
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci)
# AppleScript from stackoverflow/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
#COMMAND=$(which rz)
if [[ -f /opt/homebrew/bin/rz ]]; then
COMMAND=/opt/homebrew/bin/rz
else
COMMAND=/usr/local/bin/rz
fi
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 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 receive 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"
$COMMAND --rename --escape --binary --bufsize 4096
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi
iterm2-send-zmodem.sh内容如下:
###
# @Author: your name
# @Date: 2019-12-11 01:03:06
# @LastEditTime: 2019-12-11 01:03:21
# @LastEditors: your name
# @Description: In User Settings Edit
# @FilePath: /rzsz/iterm2-send-zmodem.sh
###
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci)
# AppleScript from stackoverflow/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
#COMMAND=$(which sz)
if [[ -f /opt/homebrew/bin/sz ]]; then
COMMAND=/opt/homebrew/bin/sz
else
COMMAND=/usr/local/bin/sz
fi
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 sc 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 fi
if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
sleep 1
echo
echo \# Cancelled transfer
else
$COMMAND "$FILE" --escape --binary --bufsize 4096
sleep 1
echo
echo \# Received "$FILE"
fi
3、设置⽂件权限
xshell下载chmod a+x /usr/local/bin/iterm2-recv-zmodem.sh /usr/local/bin/iterm2-send-zmodem.sh
4、配置 iterm2
打开iTerm2的Preferences(快捷键command+,),然后Profiles->Default->Advanced->Triggers->Edit进⼊到编辑界⾯。
在Triggers界⾯点击左下⾓的加号按钮新建两⾏,Regular Expression分别为rz waiting to receive.\*\*B0100和
\*\*B00000000000000,Action都选择Run ,Parameters分别为/usr/local/bin/iterm2-send-zmodem.sh
和/usr/local/bin/iterm2-recv-zmodem.sh
5、测试验证
在iTerm2上输⼊rz,会⾃动弹出访问来,然后选择要上传的⽂件即可。
sz下载。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论