使用zssh/rsync在本地和服务器端之间传输文件
使用zssh sz rz
Ubuntu的Terminal中不直接支持zmodem协议
参考:Using rz/sz to transfer files
其中共有三种方式:一个终端SecureCRT,或者使用zssh,或者使用screen,都是支持zmodem的。
这里选用的是zssh,命令用起来简单点,不必装一个看起来就很大的SecureCRT,也不会像screen那样用起来比较复杂
$ sudo apt install zssh #install zssh $ zssh xxx@xx.xx.xx -p port #login with zssh instead of ssh ... username@xx:~$ #in the remote shell
zssh > #this will show after press "ctrl + @", it is in local shell now
zssh > ? #get help
zssh > sz xxx #send to remote(and remote receive)
zssh > exit #go back to remote shell
username@xxx:~$ sz trainlog.txt
�B00000000000000 #then press "ctrl + @"
zssh > rz
Receiving: trainlog.txt
Bytes received: 22/ 22 BPS:257
Transfer complete
...
------------------------------------------------------------------------------Download : run sz on the remote shell before switching to transfer mode
#part of help
Usage :
then type rz(it's zssh now)
Upload: switch to transfer mode(ctrl + @) and type sz <files>
rz will be automatically run on the remote side
Tips:
- If file transfer never completes, use the -e option of sz/rz
- Transfers can be interrupted with ^C # use ^z will terminate the remote link and go back to local Terminal
- If you get stuck in rz/sz (for example you've just ran rz, but you
then decided not to transmit anything), hit a dozen ^X to stop it
- Use sz -y <files> to overwrite remote files
二段登录
$ zssh xxx@xx.xx.xx -p port ssh yyy@yy.yy.yy
使用的ssh命令格式:ssh xxx@xx.xx.xx [command];此处即先登录xxx,登录后再执行ssh yyy@yy.yy.yy
rz和sz传的文件很小,大了就不行了(估计最多只能几M);如果rz和sz之间操作时间长了些,文件就收不到了
使用rsync
rsync可以传大文件,命令形式
# 参数
-a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
--bwlimit 限速, 字节/秒
-c, --checksum 打开校验开关,强制对文件传输进行校验
--delete 删除那些DST中SRC没有的文件
-e 以ssh方式进行数据传输, ssh -p2222 指定连接2222端口
--exclude=PATTERN 指定排除不需要传输的文件模式
--include=PATTERN 指定不排除而需要传输的文件模式
--progress 显示传输进度
-P,----partial 断点续传(保留那些因故没有完全传输的文件,以便加快随后的再次传输)
-q, --quiet 精简输出模式
-r,--recursive 对子目录以递归模式处理
-v, --verbose 详细模式输出
-z, --compress 对备份的文件在传输时进行压缩处理
# 下载文件 rsync [OPTION...] [USER@]HOST:SRC... [DEST] # 上传文件 rsync [OPTION...] SRC... [USER@]HOST:DEST
rsync -P -e "ssh -p22" --progress --bwlimit=1024 root@xx.xx.xx.xx:/data/transfer/archive.zip /data/archive.zip
* 可以自动(默认)用最新的文件覆盖destination的同名文件
浙公网安备 33010602011771号