Rsync over ssh,每次都很好用。
但是,尝试 rsync 到仅允许 sftp 登录但不允许 ssh 登录的主机时,会出现以下错误:
rsync -av /source ssh user@remotehost:/target/
协议版本不匹配——你的外壳干净吗?(有关解释,请参阅 rsync 手册页)rsync 错误:compat.c(171) [sender=3.0.6] 处的协议不兼容(代码 2)
这是 rsync 手册页中的相关部分:
此消息通常是由您的启动脚本或远程 shell 工具在 rsync 用于其传输的流上产生不需要的垃圾引起的。诊断此问题的方法是像这样运行远程 shell:
Run Code Online (Sandbox Code Playgroud)ssh remotehost /bin/true > out.dat然后看看out.dat。如果一切正常,那么 out.dat 应该是一个零长度文件。如果您从 rsync 收到上述错误,那么您可能会发现 out.dat 包含一些文本或数据。查看内容并尝试找出产生它的原因。最com?原因是错误配置的 shell 启动脚本(例如 .cshrc 或 .profile)包含非交互式登录的输出语句。
在我的系统上尝试这个在 out.dat 中产生了以下内容:
ssh-dummy-shell:不允许的命令。
正如我所想,主机不允许 ssh 登录。
以下链接显示可以使用带有 sshfs 的保险丝来完成此任务 - 但是它非常慢,并且不适合生产使用。
有没有机会让 rsync sftp 工作?
事实证明 rsync 无法与具有 .bashrc 文件的远程服务器一起使用?
在本地客户端运行 rsync 时得到:
protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(180) [sender=3.0.7]
Run Code Online (Sandbox Code Playgroud)
正如这里建议的那样,删除服务器上的 .bashrc 解决了这个问题。如何在不删除 .bashrc 文件(临时)的情况下解决它?
使用以下命令从远程服务器执行 rsync 拉取时:
/usr/bin/rsync -av -e ssh --delete --chmod=a+rwx,g+rwx,o-wx --dry-run username@server:/remote/path/ /home/dir/local/path
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
receiving file list ... Invalid flist flag: 1004
rsync error: protocol incompatibility (code 2) at flist.c(2354) [Receiver=3.0.7]
Run Code Online (Sandbox Code Playgroud)
从远程到本地执行反向操作(即 PUSH)时,我得到以下信息:
building file list ... Invalid flist flag: 1004
rsync error: protocol incompatibility (code 2) at flist.c(2354) [Receiver=3.0.7]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(468) [sender=2.6.8]
Run Code Online (Sandbox Code Playgroud)
我已经尝试将参数一一删除,似乎与 -a 标志有关
环境
# local machine
Linux …Run Code Online (Sandbox Code Playgroud)