Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing username and password as arguments in a DOS copy command

Posted on 2008-10-08
17
Medium Priority
?
4,047 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
16 Comments
 
LVL 17

Accepted Solution

by:
contactkarthi earned 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Assisted Solution

by:contactkarthi
contactkarthi earned 1000 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 1000 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 1000 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 1000 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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
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…
Suggested Courses

877 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