[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

Schedule copy of files from UNIX

Hi, i am, to say the least, a UNIX novice.  I have access to Putty and WinSCP.  I would like to find a method to schedule and automate the copy of a set of files (everything with the current date) from a UNIX server to a windows directory.

can anyone point me in the right direction?
1 Solution
You have 3 problems. Scheduling. Easy in both unix and windows. Second up is transfer, WinSCP was working, but you can also turn it around and install something on the Windows side. Third is probably the most tricky. That's the download logic.

You have to test a script either on the Unix side or Windows side. It doesn't really matter which side.
If it's the unix side, you have to make sure you can reach the windows directory. On the Windows side, either share a drive, or install Filezilla Server. Test script, after that, use a cronjob to schedule it.
If it's on the Windows side, test your winscp or ftp script, then schedule the job.

Probably having a script at the unix side is easier, as otherwise you have no way to select to correct files (current date), unless the file name has this info.

So, can you FTP to the Windows directory? That would make it a lot easier to follow up on this question.
greepAuthor Commented:
Hi, thanks for your reply, you will have to, please, forgive my extreme ignorance of UNIX commands!.
I can connect to the UNIX server using WINSCP, and manually drag/drop files to a mapped windows path.

But i am not clear how, in a script I reach the Windows side.

Could you perhaps give me an example script to copy files from a UNIX directory (with the current date) to a windows path?

then, if i create the script on the UNIX server, how do I execute it from Windows?
Again, 3 problems: Scheduling/Transport/Logic
You ask how to copy files from UNIX to windows. I'm missing the TRANSPORT part. How can the Unix machine reach the Windows PC? FTP ? SMB ?
Then you ask to execute a script on UNIX from the Windows PC, but I thought you wanted to schedule it (which has to be done on the Unix side of course). Executing a script in Unix has to be done from the shell, as in an SSH session in PuttY. The scheduling of the cronjob too.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

It would probably be easiest to schedule the logic from the Linux side to pick out the dates.  Create a folder and put links to files that you like to copy from the linux side, then copy them from the windows side with winscp using schtasks or the GUI scheduler.

Create a folder to place the files that Winscp will copy from.
mkdir /path/to/link/folder

schedule a script to do the following;
find /path/to/folder -mtime 0 -exec ln -s {} /path/to/link/folder/ \;
The find command looks for files that have a mtime (modification time) of a 24 hour period, rounded up.  You can use other options for finer tuning, but this may be sufficient for your needs.

To see more details
man find

You may want to schedule another task to delete all the links before you schedule Winscp to run on Windows.
rm -r /path/to/link/folder/; mkdir /path/to/link/folder/
or if you don't have hidden dot files
rm -r /path/to/link/folder/*

or you could just place it ahead of the find command in the script.
you need to do 3 things:

1- have pscp (you can download to your windows):


2- have a unix username and password

3- schedule task to run on windows to run commands (could be a .bat file):

drivename: (e.g. c:)
cd \path]to\myfolder
c:\path\to\pscp.exe -l username -pw password hostname:/path/to/myfiles/*.*
greepAuthor Commented:
Thanks for your responses, I have found the solution.

A unix script  along these lines:

option batch abort
option confirm off
open sftp://userIid:password@unix.server
cd /server/directory
option transfer binary
get filename C:\destination\

saves as unixscript.txt

and executed from a batch file using the command line:

@echo off
C:\Progra~1\Winscp\winscp.com /console /script=C:\unixscript.txt

The batch file then added to the windows scheduler to fire at the desired time
A simple solution could have been provided by anyone. You seem to forget your original question was more intricate as indicated by "automate the copy of a set of files (everything with the current date)". Obviously, if you didn't mention that, a lot of people would have a script ready for you already. Your current script doesn't contain any of that logic.
greepAuthor Commented:
i managed to find the simpilest solution myself

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now