java使用zmodem_iterm2 使用ZModem传输文件

本文介绍了如何在Mac上利用ZModem进行文件传输,特别是通过iTerm 2与支持lrzsz的服务器进行交互。安装lrzsz,将脚本保存到/usr/local/bin/,然后在iTerm 2中设置触发器,通过rz发送文件,通过sz接收文件。此外,还提供了取消传输的方法和未来的改进计划。
摘要由CSDN通过智能技术生成

ZModem integration for iTerm 2

This script can be used to automate ZModem transfers from your OSX desktop to a server that can run lrzsz (in theory, any machine that supports SSH), and vice-versa.

The minimum supported iTerm2 version is 1.0.0.20120108

Troubleshooting

Sending a directory may fail: this is a known issue

If you are using tmux or some other terminal multiplexer, try using the -e option to sz and/or rz on your server to force escaping of more characters during transmission.

Setup

Install lrzsz on OSX: brew install lrzsz

Save the iterm2-send-zmodem.sh and iterm2-recv-zmodem.sh scripts in /usr/local/bin/

Set up Triggers in iTerm 2 like so:

Regular expression: rz waiting to receive.\*\*B0100

Action: Run Silent Coprocess

Parameters: /usr/local/bin/iterm2-send-zmodem.sh

Instant: checked

Regular expression: \*\*B00000000000000

Action: Run Silent Coprocess

Parameters: /usr/local/bin/iterm2-recv-zmodem.sh

Instant: checked

To send a file to a remote machine:

Type rz on the remote machine

Select the file(s) on the local machine to send

Wait for the coprocess indicator to disappear

The receive a file from a remote machine

Type sz filename1 filename2 … filenameN on the remote machine

Select the folder to receive to on the local machine

Wait for the coprocess indicator to disappear

Future plans (patches welcome)

Visual progress bar indicator

记得设置权限

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值