• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2830
  • Last Modified:

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?
0
mihalakj
Asked:
mihalakj
  • 3
  • 2
3 Solutions
 
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now