Solved

Passing username and password as arguments in a DOS copy command

Posted on 2008-10-08
17
3,675 Views
Last Modified: 2010-07-27
Hi,

I am trying to copy a file on to a remote server using the DOS Copy command as below...but it errors out
with a logon failure message.
C:\>copy Centricity_Extract_EPI_1.txt \\gbi-test\temp
Logon failure: unknown user name or bad password.
        0 file(s) copied.

I have two questions:
1. How can I pass the username and password as arguments in the Copy command?  
2. Can I embed the command in a .bat file and execute it as part of my build script.?

Thanks!
0
Comment
Question by:pdurbha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
17 Comments
 
LVL 17

Expert Comment

by:contactkarthi
ID: 22672734
0
 
LVL 17

Accepted Solution

by:
contactkarthi earned 250 total points
ID: 22672768
or you can map the drive first and then copy from it

http://technet.microsoft.com/en-us/library/cc749912.aspx

below is a part from the above link

NET USE X: \\NET\SHARE /USER:SCRATCH-DOMAIN\USER1 PSW1

where

\\NET = The computer name of the Advanced Server being accessed.

\SHARE = The share name.

/USER: command line parameter that lets you specify the domain, account and password that should be specified in the Session Setup SMB.

SCRATCH-DOMAIN = Domain name of the Advanced Server where the user account resides.

\USER1 = account to be validated against.

PSW1 = password that matches account on the domain.
0
 
LVL 1

Author Comment

by:pdurbha
ID: 22673432
I am able to map the shared folder on the remote server by running the command

C:\>NET USE X: \\gbi-test\temp /USER:GEMEDAMERICA\Administrator Gbi123Test123
The command completed successfully.

but when I try to copy the file over into X: it says access is denied.

C:\>copy Centricity_Extract_EPI_1.txt X:
Access is denied.
        0 file(s) copied.

What am I doing wrong here?

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 17

Assisted Solution

by:contactkarthi
contactkarthi earned 250 total points
ID: 22673595
seems like you dont have access...

check for permissions
0
 
LVL 1

Author Comment

by:pdurbha
ID: 22676053
Great..it works fine..

My other problem is I  need to create a batch file .. I have tried to embed these two commands in a bat file as below: I am not sure if this is the right way of creating a bat file ..Any thoughts?

Thanks

@echo off
echo Mapping drive on remote server to local drive on build machine...
dir C:\>NET USE X: \\gbi-test\temp /USER:GEMEDAMERICA\Administrator Gbi123Test123
echo Mapping completed...
echo copying file into temp..
dir C:\>copy Centricity_Extract_EPI_1.txt X:
echo copying completed...

0
 
LVL 8

Assisted Solution

by:Shmoid
Shmoid earned 250 total points
ID: 22678279
In lines 3 and 6 you have the following:   dir C:\>

Take that out of both lines.
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 22678439

@echo off
echo Mapping drive on remote server to local drive on build machine...
NET USE X: \\gbi-test\temp /USER:GEMEDAMERICA\Administrator Gbi123Test123
echo Mapping completed...
echo copying file into temp..
copy Centricity_Extract_EPI_1.txt X:
net use X: \\gbi-test\temp  /DELETE
echo copying completed...

as shmoid told no need for a dir C: nad you can remove the share after you have copied by using net use X: \\gbi-test\temp  /DELETE

let me know if you have any trouble
0
 
LVL 1

Author Comment

by:pdurbha
ID: 22681265
ok..here's what i did:

In my batch file, I have  this:

I get the following error message, when I double-click the batch file

Mapping drive on remote server to local drive on build machine...
'C:\' is not recognized as an internal or external command,
operable program or batch file.
Mapping completed...
copying file into temp..
'C:\' is not recognized as an internal or external command,
operable program or batch file.
copying completed...
Press any key to continue . . .

When I run the  command:

C:\>NET USE X: \\gbi-test\temp /DELETE
A command was used with conflicting switches.

More help is available by typing NET HELPMSG 3510.


C:\>NET HELPMSG 3510

A command was used with conflicting switches.

What should I do next?..Please advise as I haven't worked with batch files before.

Thanks
0
 
LVL 8

Assisted Solution

by:Shmoid
Shmoid earned 250 total points
ID: 22681336
You must have removed " dir " but did not remove " C:> " 

Line 3 should be:
NET USE X: \\gbi-test\temp /USER:GEMEDAMERICA\Administrator Gbi123Test123

Line 6 should be:
copy Centricity_Extract_EPI_1.txt X:

Notice that both do not have dir nor c:> at the beggining of the line.

If you wish to delete the mapped drive after the copy you would not specify server and share name only the drive letter, like this:
net use x: /delete


0
 
LVL 1

Author Comment

by:pdurbha
ID: 22681466
Actually, I got the bat file to work..so that issue is resolved.

so, the only issue is this:

C:\>NET USE X: \\gbi-test\temp /DELETE
A command was used with conflicting switches.

More help is available by typing NET HELPMSG 3510.

I will post the points right after this..

Thanks

0
 
LVL 8

Assisted Solution

by:Shmoid
Shmoid earned 250 total points
ID: 22681676
It's in my previous post.  You do not specify the server and share name ( \\gbi-test\temp ) when deleting a drive mapping.

The command should be:
net use X: /delete

NOT

 net use X: \\gbi-test\temp /DELETE

0
 
LVL 1

Author Comment

by:pdurbha
ID: 22683426
Thanks guys u were great!

I am trying to copy a whole directory (instead of one file) using the DOS copy command to X: but it won't do it..

I have looked into xcopy also but that didn't work..any final thoughts?

Thanks
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 22683447
glad it worked

i think the xcopy command needs a /s

something like

xcopy *.*/s x:
0
 
LVL 1

Author Comment

by:pdurbha
ID: 22683448
I wanted to split the points between u guys..but i fouled up..sorry about that
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 22683459
no problem...

 if you want to split you can always get help from the moderators
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 22683469
there is a button that says request attention in the question.. click it and ask for help there
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question