Script to copy with DOS

Reyesrj
Reyesrj used Ask the Experts™
on
How would I write a DOS script to copy a file from a server to my desktop?
Such as:

Copy
\\192.168.123.123\c$\file.doc
(Password required)

To:
C:\User\reyesrj\desktop\folder
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Adjust the variables at the beginning and save it as Whatever.cmd. You can predefine the remote system's user name, and you will be asked for the remote password (hidden input):
@echo off
setlocal
REM The UNC of the remote share:
set Share=\\192.168.123.123\c$
REM The path to the file below the share:
set FilePath=file.doc
REM User name to access the remote system; if domain user, use the format domain\user
set ShareUser=SomeDomain\SomeUser
REM The target path:
set Target=%UserProfile%\Desktop\folder
net use "%Share%" * /user:"%ShareUser%"
copy "%Share%\%FilePath%" "%Target%"
net use "%Share%" /delete

Open in new window

Commented:
If you require to copy a file where password is required, you might need to use third-party software such as CPAU.

http://www.joeware.net/freetools/tools/cpau/index.htm
Commented:
If you not worry about the password been stored on in txt file then


NET USE Z: \\192.1.168.1\sharename /u:domain\username password


::when finished delete the net drive

NET USE Z: /delete

Author

Commented:
Thanks All!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial