Solved

Passing username and password as arguments in a DOS copy command

Posted on 2008-10-08
17
3,319 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now