Archive for November, 2011

Automating File/Directory Transfer from Linux to Windows

Recently I was charged with the task of creating a script to copy some backup files from our mail server to a file server.  Now there’s a ton of information out there on various ways to do this.  You can use Samba, Likewise, FTP, etc., etc.  Samba/Likewise seem to be some of the more popular ways to do this, and it does seem to be pretty fool-proof once you’ve set it up, but I have had some issues with machine passwords changing and breaking the connection to the share.  So, I decided to go ahead and use the scripting options that come with WinSCP.

The WinSCP site does a pretty good job of putting various options out there, but I found that I still had to do a lot of trial and error to make this simple “download” work.  So, here is my, hopefully, very simple version of how to pull a file from a linux server to a windows server.

1.  Download WinSCP on your Windows file server if you haven’t already.

2.  Create a folder on the Windows server where you plan on keeping the files you’ve transferred.

3.  In the folder, create a new text document (example.txt)

4.  Edit that text file to look like this:

option batch abort

option confirm off

open root:password@ipaddress.of.linux.server

get /tmp/test*.* E:\store\

exit

This script basically says that you are opening a session as root, with your root password on the Linux server.  The get command will pull all files starting with the word “test” to your Windows machine and put it on the E drive in the Store directory.

5.  You can test the script by opening a command prompt and running:

winscp.com /script=E:\store\example.txt

If this is successful, you’re all set to create a scheduled task.  If you get a message saying that command doesn’t exist, make sure you’re in the WinSCP directory where winscp.com is stored.

6.  Open task scheduler and select Create a Basic Task on the right.  Schedule the task as you please and then select Start a Program.

7.  In the Program/Script field, browse to WinSCP.com and select that.  In the arguments field type:

/script=e:\store\example.txt

which is the location of your script.

8.  That’s pretty much it.  Make sure you have it set to run even when a user is not logged on and assign the proper credentials to run it.

, , , ,

Leave a comment