Solved

Passing username and password as arguments in a DOS copy command

Posted on 2008-10-08
17
3,253 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
symbolic link problem 6 82
Decrypting the Zepto Virus 21 605
robocopy vs xcopy vs copy 8 58
how to execute all sub dir 2 26
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

23 Experts available now in Live!

Get 1:1 Help Now