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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With