mac中使用rz,sz上傳文件


公司有幾台服務器是使用跳板機登錄上去的,離職的同事也沒有交接,現在我要去發代碼,也不知道以前他們怎么發上去的,開始以為是用git直接搞的,結果發現不是的,所以最后使用的是Mac中配合iTerm2使用rz,sz上傳/下載文件。

安裝rz / sz

使用brew安裝

brew install lrzsz

安裝完成后,在/usr/local/bin目錄下建兩個文件

/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

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

/usr/local/bin/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

文件添加完成后,給這兩文件授於可執行權限

chmod +x /usr/local/bin/iterm2-send-zmodem.sh
chmod +x /usr/local/bin/iterm2-recv-zmodem.sh

好了,上面的准備工作已經完了,接下來配置iTerm2

點擊 "Edit"配置 Triggers, 通過匹配正則觸發操作

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上傳/下載文件了,不過,我在Mac中按照上面的配置,去使用rz,sz會卡住,沒有任何彈出框出來選擇文件上傳,后面發現還需要安裝一個zssh,用ssh還不行。

brew install zssh

安裝完zssh后,就可以了,但是還是要注意,如果使用expect類的腳本,后面還是彈不出,至少我遇到的就是這樣,最終我就直接搞了個bash文件,里面就一行

zssh -i /tmp/rz.pem lc@12.8.10.79

這樣通過ssh到機器10.79這個跳板機后,再通過跳板機連接到服務器后,就能直接使用rz,sz了。

所以如果遇到配置完成后,彈不出來的就要注意看下有沒有安裝zssh,而且盡量腳本簡單些。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM