Windows utility to copy file from a remote machine

18,465

Solution 1

Make a batch file that first authenticates against the remote box, and then copies the file.

run on machine1

@echo off
net use \\\\machine2\admin$ /user:machine2\Admind2 /password:password
copy \\\\machine2\c$\data.file c:\
net use \\\\machine2\admin$ /delete

Instead of using "copy" I would also look into using the free robocopy.exe utility instead.

Solution 2

PowerShell Copy-Item does not support credentials for filesystem provider yet. So, that is ruled out.

Edit 2018 : Powershell since V5 supports remote connections. See the examples in the current documentation for Copy-Item

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

In 2011, PSExec was probably the only option you had. Also, check RemoteExec. http://www.isdecisions.com/en/software/remoteexec/

I have not tried it myself but it helps in copying files to/from a remote machine.

Solution 3

Have you looked into the putty ssh client for doing scp and a windows-based ssh server? I cannot recommend a particular ssh server for the windows platform, though I'm sure there are plenty of openssh-based applications out there, but I highly recommend the process. It is one that you'll need to be familiar with in the long-term of a digital career, anyway.

Share:
18,465
Invincible
Author by

Invincible

Updated on June 21, 2022

Comments

  • Invincible
    Invincible almost 2 years

    I am looking for native windows utility or powershell cmdlet for doing this. (Not SSH server over Windows)

    I have two machines on the same network. I want to copy files from machine1 to machine2 by executing some command on machine 2. That means I need to specify credentials for machine1 while copying the file.

    I found the PsExec tool, which only allows copy file from psexec command execution machine to remote machine and execute it automatically. But, I don't want such behavior.

    What is the best way to get the file from Machine1 onto machine2?

  • mjolinor
    mjolinor about 13 years
    copy-item does not support credentials, but new-psdrive does. Once the drive mapping is established with those credentials, you should be able to copy-item to that location without needing any further authentication.
  • ravikanth
    ravikanth about 13 years
    Oh, yes. I forgot New-PSDrive. Good workaround Rob.
  • mattmc3
    mattmc3 about 13 years
    Install Cygwin and include the OpenSSH package. Then, set up OpenSSH to run as a service. It's that simple. Here's an older (though still accurate) article about how to do this: petri.co.il/setup-ssh-server-vista.htm