Need batch file to attach remote shared dive and copy file

September 8, 2012 at 06:08:26
Specs: Windows 7
Hi,

I need a batch file that when run attaches a shared drive / directory on a server and copies a file from that server.

So say I want to run the batch file on my box, batch file should create a new drive letter on this local box say named "V:" and give me access to a directory on a remote server through this drive letter. Once the drive is mapped, the script should then copy a specific file from the directory on the server (the file will end in "050912.rpt.zip" but there will be an unknown string before this text in the filename, so the script needs to identify the correct file from just the last half of its file name). Once it has copied the correct file then I want it to delete the mapped drive, so delete the "V:".

This process will then repeat for another server. Im not interested in how this would loop or anything for now, all I want to know is how the code that I have come up with below (so so clever I know) can be amended so that it does what I explained above. (I know that "NET USE" is the command that I need to use here). Here's what I have so far:

======================================================

net use V: \\remoteserver/directory
IF EXIST v:\050912.rpt.zip
*this is obviously where i need a line to look for and copy the file*
net use V: /delete

======================================================

See More: Need batch file to attach remote shared dive and copy file

Report •


#1
September 8, 2012 at 08:32:04
copy "\\remoteserver\directory\*050912.rpt.zip"
copy "\\otherserver\directory\*050912.rpt.zip"

How To Ask Questions The Smart Way


Report •

#2
September 9, 2012 at 04:05:57
Where in the code using NET USE would this go? could post the whole thing with this bit incorporated please? would be very much appreciated, thanks for your help.

also, if I need to do this for a lot of servers, with their names/directory paths in a text file, how would I do the loop? anyone have this code?


Report •

#3
September 9, 2012 at 05:18:18
Where in the code using NET USE would this go?
It doesn't. If you're not using a different user account for the connection, there's no need.

if I need to do this for a lot of servers, with their names/directory paths in a text file, how would I do the loop?
See, that's moving the goalposts. The loop would depend on the text file, and how its data's organized.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
September 9, 2012 at 10:13:12
so I only need to use NET USE if I need to include username and password credentials then? otherwise your code would literally do it, if saved in a batch file and then run?

could you post the code on how I would do this using NET USE? just in case I need to use u/name and pwd to access the remote directory?

This is urgent :(


Report •

#5
September 9, 2012 at 10:50:22
so I only need to use NET USE if I need to include username and password credentials then? otherwise your code would literally do it, if saved in a batch file and then run?
Yep.

could you post the code on how I would do this using NET USE? just in case I need to use u/name and pwd to access the remote directory?
Guessing the share from the path takes effort. It's easier to initiate a session by binding to a known share. Specifically, by binding to IPC$ implicitly.

net use \\remoteserver /user:domain\user password
copy "\\remoteserver\directory\*050912.rpt.zip"
net use \\remoteserver /d /y

How To Ask Questions The Smart Way


Report •

Ask Question