Solved

How to copy a file from a network share to a local folder - scheduled automatically

Posted on 2011-09-02
12
322 Views
Last Modified: 2012-05-12
I'd like to somehow schedule a file (access database .mdb file) to be copied from a network share to a local folder on the C drive.  I want this to copy to run on a regular basis (possibly every day, or perhaps each time a user logs in), so that the copy is relatively current.

The network share is restricted to only certain users, so a user does need to be logged in (or identified) in order to copy the access db.

We are working with all Windows systems.  The local systems are all running Windows XP SP3.  Users log in with domain accounts.

I'm not sure how to setup something to run on a regular basis for this purpose.  Any suggestions would be welcome!

0
Comment
Question by:sah18
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 3

Expert Comment

by:Steve Gould
ID: 36473409
You could write a batch (bat) file to copy the file and then run it using the Task Scheduler. If you let me know the full path where the file is being copied from and the full path you'd like it copied to, I'll give you some code you can save as a batch file. Once this is done, take a look at this Microsoft article on how to configure the Task Scheduler in Windows XP:-

http://support.microsoft.com/kb/308569
0
 
LVL 2

Expert Comment

by:Sarcast
ID: 36473429
You should be able to accomplish this with Robocopy (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657) and a scheduled task in Task Scheduler.

If you create a reconencting network drive with log-on credentials, you should be able to cover the login problem.


Here is another location with some helpful information about Robocopy
http://theos.in/windows-server/free-download-windows-xp-2003-robocopy-software/
0
 
LVL 10

Expert Comment

by:wls3
ID: 36473437
What version of Powershell are you using? 1 or 2?
0
 
LVL 15

Expert Comment

by:The_Warlock
ID: 36473474
Just open a new Notepad session, and input the following lines:

copy <FullSourcePath>\filename <FullDestinationPath>

Save it as 'copy.bat' or whatever name you wish. Then, add a new scheduled task, when it prompts you what app to run, Browse and select your saved batch file. Then simply tell the Task Scheduler when you want it done.
You should test it before scheduling, as the above command will run it and you'll want to ensure pathname accuracy.
Alternately, you can just put the batch file in your startup folder in Windows on the PC you want to run the task.

Hope this helps.
0
 
LVL 1

Expert Comment

by:eddymel
ID: 36473513
im pretty sure that you can create a batch file for this to work so here's an article that gives you one that is very similar to want you're asking for:

http://www.pcreview.co.uk/forums/do-schedule-automatic-file-copy-t493716.html

I hope it helps!!!
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Author Comment

by:sah18
ID: 36474375
I have a couple questions about the above suggestions:

1) If a user isn't logged in at the time the batch file is scheduled to run, how can we still get it to run?  Since the user needs to be authenticated (and mapped) to the share location, I'm unclear how this would work.

2)  I've never used powershell, but thought it might be a way to accomplish this.  I'm not even sure how to find it or run it, so I don't know what version it would be.

3) If I place the batch file in the startup for any user just logging in, that seems the most logical solution (as The Warlock mentioned), but I'm concerned that the domain login script (the one that does the drive mapping) won't be completed prior to this batch file attempting to run.  Is there a way to delay the batch from running immediately??  Or can a delay be written into the batch as the first line, or is there a way to test if the "S" drive exists, before doing the copy?

Thanks much for all suggestions!
0
 
LVL 23

Expert Comment

by:DanCh99
ID: 36474496
Many backup tools offer the ability to run scripts on when they start or finish...  eg ArcServe, BackupExec, and so on.
You could add the The Warlock's one-liner in there, so the copy is done whenever your backup runs - daily, I hope!

If you use full UNC paths - eg \\servername\share\folder - then you don't need to worry about mapped drives (most backup tools have pretty elevated permissions so they can get to all folders anyway).
0
 
LVL 3

Accepted Solution

by:
Steve Gould earned 300 total points
ID: 36474612
My thought was to have the batch file passing credentials to map the drive and then un-mapping it when done, using roughly this method:-

Step 1: net use z: \\server\share password /user:domain\username /persistent
Step 2:copy c:\folder\file.txt z:\folder\file.txt
Step 3:net use /delete z:

This does however mean that you'll have a batch file sitting there with a username and password in it for all to see, which does present some problems. However, if a basic user was created with minimal permissions, any potential impact could be limited.
0
 
LVL 10

Assisted Solution

by:wls3
wls3 earned 200 total points
ID: 36475174
Create a .ps1 (Powerhsell script) with this information below and save it as Copy-Mdb.ps1 on a network share you can access from all your machine.
copy -Path ''\\Yourshare\yourfolder\yourfile.mdb" -Destination "C:\yourfolder"

Open in new window

When you create the scheduled task create it with a user account that has the appropriate privilieges.  Under the Run textbox enter the appropriate information:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "\\somenetworkshare\Scripts\Daily\Copy-Mdb.ps1" -NoProfile -WindowStyle "Hidden"

Open in new window

By saving scripts to a commonly accessible share you save yourself the trouble of having to put the script on multiple machines.  Additionally, you can refer to powershell -? in any shell to get more details on the switches available to starting powershell.exe.
0
 
LVL 6

Expert Comment

by:joeyfaz
ID: 36478700
I'm amazed nobody mentioned setting up a login script. Very simple, create a GPO that targets all of the specific groups/users and then point them to a login script to copy the file over. Below is a sample script you can use to accomplish the task
copy \\server\share\example.mdb c:\database\example.mdb /Y

Open in new window

0
 
LVL 9

Author Comment

by:sah18
ID: 36546728
I apologize for not replying back sooner.  I have been swamped and have not yet had a chance to try any of your suggestions.  I'm hoping to get back to this issue in the next week & will provide feedback then.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now