Thursday, February 25, 2010

Copy file on network drive with(out) UNC path using Cmd file

SSIS has tasks for managing files. However, sometimes it is easier to perform some operations in a batch (.bat or .cmd) file.
Some of commands in it (like Copy) have roots in DOS, so they do not support more modern options like UNC paths (just drive pats).
The following code defines drive that points to UNC path. It is also an opportunity to specify login and password needed to access remote folder (otherwise everything will be executed in context of current user).


Rem Define Drive for target UNC path
net use L: \\Server.Domen\SharedPath /user:Domen\User Password

Rem Perform operation
copy L:\SubFolder\original.txt F:\Folder\SubFolder\Destination.txt

Rem Wait for process to finish
sleep 30

Rem Remove Drive
net use L: /delete

No comments:

Post a Comment