ROBOCOPY network UserName/Password
If you need to copy something using robocopy to remote host where additional authentication is required you should send username/password somehow. Robocopy.exe does not provide network authentication by itself. So to provide username and password for robocopy.exe we can use NET USE to open IPC$ share to destination host and execute our robocopy code.
- Note: There is UNC path used, so keep in mind to have source and destination folders shared.
- Script language: cmd / bat
NET USE \\RemoteServerName\IPC$ /u:server\user *password*
robocopy \\Source\ \\RemoteServerName\DestinationDir\ /XD * /Z /MIR /LOG+:c:\temp\log.log
NET USE \\RemoteServerName\IPC$ /D
Code comments:
/XD * – exclude ALL sub directories
/Z – copy files in restartable mode (survive network glitch)
/D – close IPC$ share to make our script clean
- Script language: PowerShell
- Has parameters to customize script
- Can send log file by email.
# IPC$ share options #
$IPCHost = "host_name" # Host name to create IPC$ share with
$IPCUser = "domain\user" # Authentication
$IPCPwd = "Pa$$w0rd" # for IPC$ share
# Copy TO settings #
$DstHost = "host_name" # Destination Host Name
$DstDir = "root_share\folder\name" # Destination Directory Path
# Copy FROM settings #
$SrcHost = "host_name" # Source Host Name
$SrcDir = "root_share\folder\name" # Source Directory Path
# E-Mail Settings #
$LogPath = "c:\full_path.log" # Full path to log file (c:\temp.name.log)
$EmailTo = "email@domain.com" # Recipient email address
$EmailFrom = "email@domain.com" # Sender email address
$EmailSubj = "subject_here" # Letter Subject
$EmailBody = "body_here" # And body
$EmailSmtpSrv = "server_name" # SMTP server name (FQDN)
# Parameters (robocopy keys) #
$Params = "/XD * /Z /MIR" # Specify needed robocopy.exe parameters here
# Action Block #
NET USE \\$IPCHost\IPC$ /u:$IPCUser $IPCPwd
robocopy.exe \\$SrcHost\$SrcDir\ \\$DstHost\$DstDir\ $Params /LOG:$LogPath
NET USE \\$IPCHost\IPC$ /D
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubj -Body $EmailBody -SmtpServer $EmailSmtpSrv -Attachments $LogPath
Categories: Scripting
thanks a TON!
it works like a charm ! Thx
Nice tip, thank you!
HI
I think there’s a hiccup: the NET USE bit looks like it’s missing a drive letter’ and this drive letter is meant to be referred to in the robocopy.exe bit:
LIke NET USE Z: \\REMOTESERVER\REMOTEDIR /U:REMOTEUSER REMOTEUSERPASS
ROBOCOPY.EXE LOCALDIR|UNC Z: $PARMS
NET USE Z: -D
Otherwise, you are mapping a letterless drive; and not referring to it in the copy if I am not mistaken.
Thanks for a great article.
Vic
I made a comment earlier, elaborating on my ignorance. please discard it; your work rocks.
Great script. Thanks for sharing
To copy files from one system to another remote system follow these simple steps:
1) login to the remote system using this command
NET USE \\RemoteServerName\IPC$ /u:username password
2)Go to the directory in which we have the file for example cd c:progfiles/
3) Then use this commad
ROBOCOPY “file name to be copied” “\\ip address of the remote machine\pathname\”file name to be copied” /MIR
Thanks man! What a great post… to the point and very clear!
use robocopy
I love you
Thank YOu so Much! congrats
Thanks the script it works like a charm, i am wondering if could limit the notification over the email if it failed to copy any content on any destination.
Please help what parameters to use to get email for a failed output.
I am using different domain user, I am getting user name or password is incorrect.
Tremendous things here. I’m very satisfied to see your article.
Thank you a lot and I am taking a look forward to touch you.
Will you please drop me a e-mail?
Thanks, Is there any way to hide password, so if somebody open batch script can not see user and pass?
Good Solution for small Server rooms
Two words: “THANK YOU”