Command line copy across domains

I need to be able to copy a file via command line from a server in one win2k3 domain to another server in a different win2k domain.  There is no trust between the domains, but I do have administrator credentials that I can pass in the command line to execute the copy.  I checked copy, xcopy and robocopy but none of these appear to have a function that allows you to specify the username and password you would like to connect as.  Any suggestions on how to do this type of copy via command line?
mihalakjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rokovCommented:
Use net command to map network drive and then use any copy utility.
0
mihalakjAuthor Commented:
i need to copy via unc path name and can't map the drive first due to a script i've cobbled together .  Looks like I may need to start over.
0
rokovCommented:
OK. Then you may use the same net command to authenticate to remote server only. Your local server will cache used credentials and copy with UNC path shall work.
Example:
net use * //serv1/c$ <password> /user:<username>
copy test.txt //serv1/c$/tmp/*.*
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

oBdACommented:
You need to connect to the IPC$ shares on the machine in the untrusted domain (assuming you're running this in the trusted domain, and you have the necessary permissions to access the source/target folder in the trusted domain) and you should disconnect these once the copy is done; you didn't say where the source is, where the target, where the script is running, and whether you have enough permissions to connect to the "trusted" server.
The probably easiest way to do that is to create a batch file on the fly and then run this batch (and delete it afterwards again):

@echo off
net use \\UntrustedServer\IPC$ TopSecret /user:TheOtherDomain\TheOtherUser /persistent:no
if not errorlevel 1 robocopy ...
net use \\UntrustedServer\IPC$ /delete

You could try to put that together into one string; "&&" will only execute the following command if the previous command was successful, a single "&" will run the following command after the first one (and concatenating with || will only run the following command if the previous one was unsuccessful), but that will be one hell of a line (especially if you might have to work with quotes for the paths).
This should give you a first idea (can't test it at the moment:
cmd.exe /c /s "net use \\UntrustedServer\IPC$ TopSecret /user:TheOtherDomain\TheOtherUser /persistent:no && robocopy ... & net use \\UntrustedServer\IPC$ /delete"
0
rokovCommented:
Solutions were provided.
Suggest: PAQ + assign points
Do not see any rationale for deletion.
0
mihalakjAuthor Commented:
none of the provided solutions were applicable to the constraints of my script.  It was not possible to pass credentials during the copy command.  Its possible to pass them before the copy command, but the constraints of the script did not allow this as an option.  I ended up having to scrap the script and find another way.  Help was provided in good faith though, so I am not adverse to awarding points.  I'm a bit new at experts exchagne so hopefully I can do this correctly. Stand by
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.