简体   繁体   中英

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.

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.

Does anyone know how to do this?

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.

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.

"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?

"linux machine to a windows" can be done two ways.

  1. Linux is client. Windows runs an FTP or SCP or SSH server. Linux has a client and pushes the file to Windows. Look at FileZilla for free windows FTP server. Also, windows often has an FTP service that's turned off. Turn it on.

  2. 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.

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 country list of sftp clients.

I haven't used it in years now, but you could try Unison from http://www.cis.upenn.edu/~bcpierce/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.

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. You will use this ID in step 4
  2. Become 'root'
  3. mkdir /mnt/sharename
  4. 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

  5. Edit /root/smblogin and put the following two lines in it

    username=YOUR_WINDOWS_USERNAME
    password=YOUR_WINDOWS_PASSWOD

  6. Log in as the user from step 1.

  7. Try mounting the share: mount /mnt/sharename
  8. 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/

  9. Use cron to run the script.

    1. Type 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 . And Windows support some kind of cron-like operation in its management stuff, don't they?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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