简体   繁体   English

自动将文件从Linux计算机复制到Windows计算机

[英]Automatically copying files from a Linux machine to a Windows machine

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. 我正在寻找像scp,rsync,sftp这样简单安全的东西。 Unfortunately, I'm at a loss of how to set this up on the Windows machine. 不幸的是,我不知道如何在Windows机器上设置它。

Does anyone know how to do this? 有谁知道如何做到这一点?

You can try mounting the Windows drive as a mount point on the Linux machine, using smbfs; 您可以尝试使用smbfs将Windows驱动器作为挂载点安装在Linux计算机上; you would then be able to use normal Linux scripting and copying tools such as cron and scp/rsync to do the copying. 然后,您就可以使用普通的Linux脚本和复制工具(如cron和scp / rsync)进行复制。

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. 你可以在cygwin中找到windows的rsync,你可以在windows框上设置一个rsync服务器,然后在linux机器上运行一个cron作业,将所有文件运行到windows机器上。 We used to do that and it worked fine. 我们曾经这样做,它运作良好。

"I'm at a loss of how to set this up on the Windows machine." “我无法在Windows机器上进行设置。” Windows is the client or the server? Windows是客户端还是服务器? At a loss means what, specifically? 亏本意味着什么,特别是? What can't you do? 你不能做什么?

"linux machine to a windows" can be done two ways. “linux机器到windows”可以通过两种方式完成。

  1. Linux is client. Linux是客户端。 Windows runs an FTP or SCP or SSH server. Windows运行FTP或SCP或SSH服务器。 Linux has a client and pushes the file to Windows. Linux有一个客户端并将文件推送到Windows。 Look at FileZilla for free windows FTP server. 查看FileZilla免费的Windows FTP服务器。 Also, windows often has an FTP service that's turned off. 此外,Windows通常有一个关闭的FTP服务。 Turn it on. 打开它。

  2. Windows is client. Windows是客户端。 Windows periodically pulls the file from the linux server. Windows定期从Linux服务器提取文件。 This is easier, since Linux already has all the necessary servers available. 这更容易,因为Linux已经拥有所有必需的服务器。 You do, howeveevr, need to start them on Linux. 不管怎么说,你需要在Linux上启动它们。

There are scores of sftp, scp clients for Windows. Windows上有很多sftp,scp客户端。 Windows comes with an ftp client. Windows附带一个ftp客户端。 Google for sftp client. 谷歌的sftp客户端。 You'll find WinSCP , Putty , filezilla , and list free country list of sftp clients. 您将找到WinSCPPuttyfilezilla和sftp客户端列表免费国家/地区列表。

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. 它可以使用'smbclient'来完成,它的行为很像FTP客户端到Windows共享。 Check out the manpage: man smbclient and look for ways to script it with the -c option, or man expect to drive it. 查看联机帮助页: man smbclient并查找使用-c选项编写脚本的方法,或者man expect驱动它。

Here's how I'd probably do it though: 这是我可能会这样做的方式:

  1. 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. 以此用户身份登录并键入“id”,然后获取数字ID。 You will use this ID in step 4 您将在步骤4中使用此ID
  2. Become 'root' 成为'根'
  3. mkdir /mnt/sharename
  4. Edit your /etc/fstab file and add an entry something like this. 编辑/ etc / fstab文件并添加类似这样的条目。 Replace the user ID of 500 with your user ID. 用您的用户ID替换用户ID 500。 Replace sharename with your windows share name. 用您的Windows共享名称替换sharename。 Replance WINDOWSHOSTNAME with your host name or IP address. 用您的主机名或IP地址替换WINDOWSHOSTNAME。 If you don't know the shares, run smbclient -L WINDOWSHOSTNAME . 如果您不知道共享,请运行smbclient -L WINDOWSHOSTNAME

    //WINDOWSHOSTNAME/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0

  5. Edit /root/smblogin and put the following two lines in it 编辑/ root / smblogin并在其中添加以下两行

    username=YOUR_WINDOWS_USERNAME
    password=YOUR_WINDOWS_PASSWOD

  6. Log in as the user from step 1. 以步骤1中的用户身份登录。

  7. Try mounting the share: mount /mnt/sharename 尝试安装share: mount /mnt/sharename
  8. If that succeeds, then write a script to do it automatically. 如果成功,则编写脚本以自动执行。 Let's call it 'backup.sh': 我们称之为'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/

  9. Use cron to run the script. 使用cron运行脚本。

    1. Type crontab -e 输入crontab -e
    2. Put the following in the file: 将以下内容放入文件中:

    PATH=/bin:/usr/bin
    # Backup at 2:15 AM every day. Run 'man 5 crontab' for help on the time format
    15 2 * * * /path/to/backup.sh

You may try WinSCP and its scripting support . 您可以尝试WinSCP及其脚本支持 And Windows support some kind of cron-like operation in its management stuff, don't they? Windows在其管理中支持某种类似cron的操作,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM