Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to setup an automatic copy from Folder to Folder. 2

Status
Not open for further replies.

ironhide1975

Programmer
Feb 25, 2003
451
0
0
US
I'm developing a system that needs to automatically copy a file dropped in one folder, on one server.. to .. another folder on another system over the network. Is there a way to have Windows automatically copy a file from folder to folder everytime a new file is dropped in?

 
you may have many options. you can create a batch file + windows scheduler to do that. or you can create script to setup time and copy it.

Robert Lin, MS-MVP, MCSE & CNE
Windows, Network, Internet, VPN, Routing and How to at
 
Chicago Tech Net, how would I go about setting this up with Wndows scheduler.

 
On the start menu under Accesories-System Tools will you find the task scheduler.

Start it up and click schedule task which will bring up the task schedule wizard which should be straight forward to use. Basically browse to your batch file and set times for it to run.

I would create a user with enough right to do the task in your script as you will need to supply a user name and password and if you use your login profile and change password it will stop the task from running.

Also I would make sure that you can run the batch script manually and that it works 100% before you schedule it.

---
Make the best use of what is in your power, and take the rest as it happens.
 
Ok I found an alternative, I can create a batch file that copies the files and then run the batch file from ASP. The problem I'm dealing with now is security to get to the mapped drive/other server. But I think our NT guy here can help me with that.

Thanks again guys, you rock!

 
You can have your batch file map up folder on another machine. Something like this would do

NET USE M: \\servername\c$ /user:DOMAINNAME\administrator password

then once your copy part is finished have the command

Net use M: /delete
To remove the mapped drive


---
Make the best use of what is in your power, and take the rest as it happens.
 
I already have the drive mapped, how to I just insert the username and password?

 
Ok so the batch file works fine when I double click it on the server, but when I run it through ASP I get that it failed.

set shell = Server.CreateObject("WScript.shell")
strPath = Server.MapPath("/staff/scripts/copy.bat")
mess=shell.Run(strPath, 2, true)

If mess = 0 Then
Response.Write "<b>FTP successful.</b>"
Else
Response.Write "<b>FTP failed.<b>"
End If

 
I dont know ASP that well but I would think that it would be easier to just schedule the task in the task scheduler as you can then have it running with a user that has enough rights on both machines for instance a domain admin.

Which could be the reason for it to fail when you run it through ASP that you don't run the batch file with enough right to perform the task.

---
Make the best use of what is in your power, and take the rest as it happens.
 
Is there anyway to create the schedule to run anytime the folder is changed and thats it? Having the task run constantly is going to be draining on the system.

 
Do you require to copy the file often? Like setting it up to copy it every 30 min isnt good enough?

It should be possible to check when the file was changed and only copy it once it has changed from the last time it was copied in your batch file. But it would make the script a bit more complicated and I'm not sure if its possible to do that kind of lookup with the commands builtin.

There is a tool called robocopy from ms free download which can check file change etc so you might want to look into using it.

---
Make the best use of what is in your power, and take the rest as it happens.
 
I'm trying to avoid using an external program. But let me give you a bit of background on this.

We have a document archiving system called Report to Web (from Redwood Software). We have a watch program that will take any file dropped in this Watch folder, and import it into Report to Web.

I have tinkered with both SmartASP, and ASPUpload both which seem to do what I need them to do. But for some reason I keep getting stopped at some point for getting the file from the web server, over to the Report to Web server. I have tried using SmartASPUpload and it can't do virtual links. ASPUpload gives me an error, and the batch file works when I double click it, but not when its scheduled and it runs.

Any help is appreciated, thanks guys.

 
Robocopy is a more feature rich xcopy and as I said its a free download from Microsoft.

Now if your batch file fails when it scheduled it wont make any diffrence in using robocopy.

Most of the problems people have with schedule tasks and them not working is down to the rights of the user that you specified when you setup your scheduled task. So I would make sure that you specified a user with enough domain rights and that you typed the right password.

Because if the script works manually it should work fine scheduled.

---
Make the best use of what is in your power, and take the rest as it happens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top