Bat file to copy files from one computer to another

  • Thread starter Thread starter jsaumer
  • Start date Start date
J

jsaumer

Hello,

I am wondering how to do the following:

Copy all the files in a difrectory to a remote directory, overwriting
any files already there.

There will need to have domain authentication built in, and it needs
to do it wihtout prompting the user because it will be a scheduled
task.

Any and all help will be greatly appreciated!
 
Hello,

I am wondering how to do the following:

Copy all the files in a difrectory to a remote directory, overwriting
any files already there.

xcopy Source Destination /y

/y means to overwrite.

You can add /D to only overwrite with newer files.

And /s to do subdirectories.

And /r /h to include Read-Only (bit set) or Hidden files.

/c to continue on errors if one or some files fail (due to locking etc.)
There will need to have domain authentication built in, and it needs
to do it wihtout prompting the user because it will be a scheduled
task.

If authentication by the current "user" or "Computer" is already possible
the above just works:

xcopy Source \\Server\Destination /y

Or you can map the drive.

The key is that the process which runs the batch must be able to
authenticate
and have enough permission to do the task.

When you schedule a submitted batch file (Task Scheduler) you are allowed
to provide credentials (user name and password) for running the batch.

If you use a Computer account (startup batch or scheduled job) then the
COMPUTER account is the one that must have access with both the
SHARE and the NTFS permissions on the server.
Any and all help will be greatly appreciated!

Let us know if you have more quesitons or don't understand something....
 
xcopy Source Destination /y

/y means to overwrite.

You can add /D to only overwrite with newer files.

And /s to do subdirectories.

And /r /h to include Read-Only (bit set) or Hidden files.

/c to continue on errors if one or some files fail (due to locking etc.)


If authentication by the current "user" or "Computer" is already possible
the above just works:

xcopy Source \\Server\Destination /y

Or you can map the drive.

The key is that the process which runs the batch must be able to
authenticate
and have enough permission to do the task.

When you schedule a submitted batch file (Task Scheduler) you are allowed
to provide credentials (user name and password) for running the batch.

If you use a Computer account (startup batch or scheduled job) then the
COMPUTER account is the one that must have access with both the
SHARE and the NTFS permissions on the server.


Let us know if you have more quesitons or don't understand something....

It works like a charm! Thanks!

To keep from overwhelming the remote server with a ton of SQL backups,
is there a way for the bat to delete everything in the remote fodler
without prompting the user if they are sure?
 
To keep from overwhelming the remote server with a ton of SQL backups,
is there a way for the bat to delete everything in the remote fodler
without prompting the user if they are sure?

Yes and VERY dangerous unless YOU are sure:

del /q FilesToDelete

You could do an "if exists" test to make sure you got the copy:

if exists \\Server\Dest\Filename del localPath\Filename

You can also cycled through the local file names with a For-In-Do
loop (double % signs needed for this to run in a batch, single if
you run it interactively to test):

cd LocalDirectory
for %%a in (*.*) do if exist "\\Server\Share\%%a" del "%%a"
 
Back
Top