我使用 rsync 在本地目录和远程主机之间同步文件。我还使用 plink 自动输入 SSH 密码。
我不知道如何将 rsync 与 plink 一起使用。我认为语法应该是这样的:
rsync -args --rsh="plink user@remote" local_dir/ :/remote_dir
但我收到“拒绝访问”消息。有办法解决吗?简单吗?
已编辑反映出我认为语法应该是什么样的。我以前犯过很大的错误。
答案1
这似乎是 cygwin 和本机 Win32 程序之间的 stdin/stdout 重定向不兼容。
有人设法制作了一个包装器来解决这个问题:
http://diario.beerensalat.info/2009/08/18/new_cygnative_version_1_2_for_rsync_plink.html
用法如下:
rsync -args -e="cygnative plink" local_dir/ user@remote:/remote_dir
答案2
这是一个解决该问题的完整批处理文件:
rem This is file: copy_win_inifiles_to_linux_via_rsync_with_pagent.bat
rem This is what I want:
rem
rem Windows with Putty+Pagent -> rsync -> Linux
rem
rem pagent.exe is already loaded with my ssh-key
rem This ssh-key shall make the authentication to the remote rsyncd/Linux
rem
rem Environment for this Batch-file:
rem
rem plink.exe for Windows, derived from cygwin
rem download here:
rem http://it-em.net/joomla/downloads/rsync.zip
rem with german dokumentation in http://it-em.net/joomla/index.php?option=com_content&view=article&id=49&Itemid=54cms/front_content.php
rem cygnative.exe is needed from plink.exe (putty-suite)
rem so that plink.exe works together wird rsync.exe
rem download cygnative here:
rem http://diario.beerensalat.info/2009/08/18/new_cygnative_version_1_2_for_rsync_plink.html
rem
rem Filetree looks like this:
rem + copy_win_inifiles_to_linux_via_rsync_with_pagent.bat
rem + bin/
rem + rsync.exe
rem + cygwin1.dll # needed from rsync.exe
rem + cygiconv-2.dll # needed from rsync.exe
rem + cyggcc_s-1.dll # needed from rsync.exe
rem + cygnative.exe # standalone-program
rem + plink.exe # from putty-suite, standalone-program
rem + ini/ # Here are the file which shall be transferred
rem + bla.ini
rem + foo.ini
rem
rem our current working is the same where this bat-file is
set SRC_DIR=./ini/
set DST_USER=yourusername
set DST_SERVER=your-linux-server.somewhere.com
set DST_PORT=22
set DST_DIR=/home/yourusername/what/ever/ini
bin\rsync.exe -v -d --delete -e="./bin/cygnative.exe ./bin/plink.exe -P %DST_PORT%" %SRC_DIR% %DST_USER%@%DST_SERVER%:%DST_DIR%
答案3
我通常通过 ssh 执行 rsyncs,操作类似如下:
rsync -args -e "ssh -i .ssh/my-key" 用户@主机名:/dir1 /dir2
您可以尝试替换适当的 plink 或 putty 命令。