Solved

Passing username and password as arguments in a DOS copy command

Posted on 2008-10-08
17
3,397 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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