17

I'm looking for a way to copy files over to/from remote Windows hosts, and need to provide domain user credentials as part of the process, similar to the way psexec does.

I know I can use net use to map the target directory to a drive letter and use xcopy, and I know psexec can upload files to be executed on the remote machine and then delete them, but I'm looking for a way to distribute files to remote hosts that will not be as awkward to use as net use and xcopy.

2
  • why can't you use psexec if it does what you need?
    – Snark
    Mar 15, 2010 at 21:23
  • it deletes the files afterwards, and it tries to execute them before that :-) i need to just transfer files around
    – radai
    Mar 16, 2010 at 3:55

4 Answers 4

18

XCopy supports UNC paths.

C:\>xcopy \\computer1\source\*.* \\Computer2\target
C:\>xcopy \\computer1\source\FakeFileNAme.txt C:\

I would imagine with the use of RunAs you should be able to feed it whichever credentials you'd like.

HTH

5
  • FWIW, practically everything on Windows supports UNC paths - it is not xcopy-specific. Mar 15, 2010 at 20:59
  • will runas allow me to use a user that cannot log on to the local machine to transfer files to the remote machine ?
    – radai
    Mar 16, 2010 at 3:54
  • 1
    I haven't used RunAs off a domain in quite a while, but I think the "RunAs /netonly" option will do what you're looking for. Mar 16, 2010 at 4:22
  • what is the syntax for copying to a remote folder location, say to C:\temp of the remote computer? xcopy .\local_file \\remote_computer\??? ?
    – Chris F
    Oct 26, 2021 at 18:49
  • I tried xcopy .\local_file "\\10.220.x.x\c$\temp` and I get "Invalid drive specification
    – Chris F
    Oct 26, 2021 at 19:18
4

You can use robocopy. just open a command window and type robocopy /? to see available options.

1
  • I didn't notice anything in robocopy for specifying credentials. Does it support that?
    – Eric
    Apr 6, 2012 at 22:18
1

Not exactly a "small utility", but the pywin32 package of Python for Windows has win32net and win32wnet modules that could be helpful with scripting credentials and such.

1

Since this question and answers, Powershell now supports remote copy.
See the documentation for Copy-Item
You may also need to Enable PSRemoting (depending on your target machine)

Example 5: Copy a file to a remote computer

$Session = New-PSSession -ComputerName "Server01" -Credential "Contoso\PattiFul"
Copy-Item "D:\Folder001\test.log" -Destination "C:\Folder001_Copy\" -ToSession $Session
1
  • Copy-Item -Recurse FolderNameHere -Destination \\OtherMachine\C$\Temp Sep 20, 2018 at 1:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .