自动将文件从 Linux 机器复制到 Windows 机器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/289760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatically copying files from a Linux machine to a Windows machine
提问by
I need to automatically copy files from a linux machine to a windows one every day.
我需要每天自动将文件从 Linux 机器复制到 Windows 机器。
I'm looking for something simple and secure like scp, rsync, sftp. Unfortunately, I'm at a loss of how to set this up on the Windows machine.
我正在寻找一些简单而安全的东西,比如 scp、rsync、sftp。不幸的是,我不知道如何在 Windows 机器上进行设置。
Does anyone know how to do this?
有谁知道如何做到这一点?
回答by Avi
You can try mounting the Windows drive as a mount point on the Linux machine, using smbfs; you would then be able to use normal Linux scripting and copying tools such as cron and scp/rsync to do the copying.
您可以尝试使用 smbfs 将 Windows 驱动器挂载为 Linux 机器上的挂载点;然后,您就可以使用普通的 Linux 脚本和复制工具(例如 cron 和 scp/rsync)进行复制。
回答by Ulf Lindback
You can find rsync for windows in cygwin, with that you can setup a rsync server on the windows box and run a cron job on your linux machine rsync'ing all the files to the windows machine. We used to do that and it worked fine.
您可以在 cygwin 中找到适用于 Windows 的 rsync,您可以在 Windows 机器上设置一个 rsync 服务器,并在您的 linux 机器上运行 cron 作业,将所有文件同步到 Windows 机器。我们曾经这样做过,而且效果很好。
回答by S.Lott
"I'm at a loss of how to set this up on the Windows machine." Windows is the client or the server? At a loss means what, specifically? What can't you do?
“我不知道如何在 Windows 机器上进行设置。” Windows是客户端还是服务器?不知所措,具体是什么意思?你不能做什么?
"linux machine to a windows" can be done two ways.
“linux machine to a windows”可以通过两种方式完成。
Linux is client. Windows runs an FTP or SCP or SSH server. Linux has a client and pushes the file to Windows. Look at FileZillafor free windows FTP server. Also, windows often has an FTP service that's turned off. Turn it on.
Windows is client. Windows periodically pulls the file from the linux server. This is easier, since Linux already has all the necessary servers available. You do, howeveevr, need to start them on Linux.
Linux是客户端。Windows 运行 FTP 或 SCP 或 SSH 服务器。Linux 有一个客户端并将文件推送到 Windows。查看FileZilla以获得免费的 Windows FTP 服务器。此外,Windows 通常有一个已关闭的 FTP 服务。打开它。
Windows 是客户端。Windows 会定期从 linux 服务器中提取文件。这更容易,因为 Linux 已经拥有所有必要的服务器可用。但是,您确实需要在 Linux 上启动它们。
There are scores of sftp, scp clients for Windows. Windows comes with an ftp client. Google for sftp client. You'll find WinSCP, Putty, filezilla, and list free countrylist of sftp clients.
有许多用于 Windows 的 sftp、scp 客户端。Windows 带有一个 ftp 客户端。Google for sftp 客户端。您将找到WinSCP、Putty、filezilla并列出sftp 客户端的免费国家/地区列表。
回答by S.Lott
I haven't used it in years now, but you could try Unison from http://www.cis.upenn.edu/~bcpierce/unison/
我已经很多年没有使用它了,但是您可以从http://www.cis.upenn.edu/~bcpierce/unison/尝试 Unison
It could be done with 'smbclient', which acts much like an FTP client to a Windows share. Check out the manpage: man smbclient
and look for ways to script it with the -c
option, or man expect
to drive it.
这可以通过“smbclient”来完成,它的作用很像 Windows 共享的 FTP 客户端。查看联机帮助页:man smbclient
并寻找使用该-c
选项编写脚本或man expect
驱动它的方法。
Here's how I'd probably do it though:
不过,我可能会这样做:
- Pick which user you're going to be when you sync the files. Log in as this user and type 'id', and get the numeric ID. You will use this ID in step 4
- Become 'root'
mkdir /mnt/sharename
Edit your /etc/fstab file and add an entry something like this. Replace the user ID of 500 with your user ID. Replace sharename with your windows share name. Replance WINDOWSHOSTNAME with your host name or IP address. If you don't know the shares, run
smbclient -L WINDOWSHOSTNAME
.//WINDOWSHOSTNAME/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0
Edit /root/smblogin and put the following two lines in it
username=YOUR_WINDOWS_USERNAME
password=YOUR_WINDOWS_PASSWODLog in as the user from step 1.
- Try mounting the share:
mount /mnt/sharename
If that succeeds, then write a script to do it automatically. Let's call it 'backup.sh':
#!/bin/sh
df | grep -q /mnt/sharename
if test $? -ne 0 ; then
mount /mnt/sharename
fi
cp -r /path/to/dir /mnt/sharename/destination/Use cron to run the script.
- Type
crontab -e
- Put the following in the file:
PATH=/bin:/usr/bin
# Backup at 2:15 A.M. every day. Run 'man 5 crontab' for help on the time format
15 2 * * * /path/to/backup.sh- Type
- 选择同步文件时您将成为哪个用户。以该用户身份登录并输入“id”,然后获取数字 ID。您将在步骤 4 中使用此 ID
- 成为“根”
mkdir /mnt/sharename
编辑您的 /etc/fstab 文件并添加类似这样的条目。将用户 ID 500 替换为您的用户 ID。将 sharename 替换为您的 Windows 共享名称。用您的主机名或 IP 地址替换 WINDOWSHOSTNAME。如果您不知道份额,请运行
smbclient -L WINDOWSHOSTNAME
。//WINDOWSHOSTNAME/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0
编辑 /root/smblogin 并将以下两行放入其中
username=YOUR_WINDOWS_USERNAME
password=YOUR_WINDOWS_PASSWOD以步骤 1 中的用户身份登录。
- 尝试挂载共享:
mount /mnt/sharename
如果成功,然后编写一个脚本来自动执行。我们称之为“backup.sh”:
#!/bin/sh
df | grep -q /mnt/sharename
if test $? -ne 0 ; then
mount /mnt/sharename
fi
cp -r /path/to/dir /mnt/sharename/destination/使用 cron 运行脚本。
- 类型
crontab -e
- 将以下内容放入文件:
PATH=/bin:/usr/bin
# Backup at 2:15 A.M. every day. Run 'man 5 crontab' for help on the time format
15 2 * * * /path/to/backup.sh- 类型
回答by che
You may try WinSCPand its scripting support. And Windows support some kind of cron-like operation in its management stuff, don't they?