Windows: use Robocopy to copy files over the network

Windows robocopy tutorial

Robocopy is a powerful and efficient Windows-based tool for copying files over the network. It is available on all versions of Windows, including Windows 10, Windows 11, Windows Server 2012 R2, Windows Server 2016 and Windows Server 2022. In my humble opinion, it's a tool you need to know!

Although this article focuses on the use of Robocopy, I'm going to cover the creation of a share under Windows 11 succinctly, as this is not the purpose of the article.

1. Creating a share in Windows 11

To transfer files from machine A to machine B, machine B must have a share ready to receive the transferred data over the network. This can be done using Robocopy, xcopy or the PowerShell Copy-Item command. Finally, there's an alternative: using administrative shares, of which "c$" is one, to directly access the root of the local disk "C" where Windows is installed.

To create a share simply called "Sharing on Windows 11 (or another version), it's very simple. Just create the folder, e.g. "C:\Share", then share it:

1 - Right click " Properties

2 - Tab " Share "then " Advanced sharing "(you can also use "Share...")

3 - Check the " Share this folder "and assign the name Share "(or something else)

4 - Click on the " Authorizations "To read, simply retrieve information about the share, in the sense of remote share to local machine.

Windows 11 - Creating a share

5 - Validate: the share is created - Permissions and other settings can be modified at any time

To view the active shares on a machine using the command line :

# MS-DOS control
net share
# PowerShell command
Get-SmbShare

2. Using Robocopy to transfer files

Now that the share is in place, let's see how to copy files from the local machine to the remote share.

  • Source : contenu du dossier « C:\Users\Tutobox\Documents\ »
  • Destination : le partage « \\W11\Partage »

Without options, Robocopy can be used as follows:

robocopy

But the tool has so many practical options that it would be a shame to miss out. Let's use this template instead:

robocopy   /E /Z /ZB /R:5 /W:5 /TBD /NP /V /MT:16

Ready to test? Run a command prompt or PowerShell console as admin (right-click).

If we take the previous model and apply our values, the result is :

robocopy "C:\Users\Tutobox\Documents\" "\W11\Partage" /E /Z /ZB /R:5 /W:5 /TBD /NP /V /MT:16

Robocopy's output is complete (a nice touch), showing all the files copied, with the full path, as well as a summary showing the number of successes and failures, and the transfer rate. To reverse the copy direction, simply invert the two paths in the command.

Robocopy Example

This command has lots of options, but what are they for? Let me explain, because the idea is not to use the command foolishly...! I've deliberately included some options to show you that you can customize the Robocopy command to the max, but it's up to you.

  • /S – Copie les sous-répertoires, mais pas les vides.
  • /E – Copie les sous-répertoires, y compris les vides.
  • /Z – Copie les fichiers en mode redémarrable. En mode redémarré, si une copie de fichier doit être interrompue, Robocopy peut reprendre là où il s’est arrêté au lieu de recopier l’intégralité du fichier.
  • /ZB – Utilise le mode redémarrable. Si l’accès est refusé, utilise le mode de sauvegarde.
  • /R:5 – Réessaie 5 fois en cas d’échec (la valeur par défaut est 1 million : c’est beaucoup et même bloquant !).
  • /W:5 – Attends 5 secondes entre chaque essai (la valeur par défaut est 30 secondes).
  • /TBD – Attendre que les noms de partage soient définis
  • /NP – N’affiche pas le pourcentage copié.
  • /V – Mode bavard pour afficher les fichiers ignorés.
  • /MT:16 – Faire des copies multithreadées, avec 16 threads dans cet exemple (par défaut 8 – maximum : 128).

Don't forget to run some tests, as certain options can have a real impact on performance! Network throughput can be improved, but the machine is under greater strain, so you need to find the right compromise. The "/MOV" option is not used in our example, but it allows data to be moved with Robocopy, not copied.

Robocopy is also your ally:

robocopy /?

Another function I often use with Robocopy is the mirror function (/MIR), which synchronizes the source and destination so that one mirrors the other. You can also synchronize rights (/SEC).

robocopy   /MIR /SEC

From the help :

  • /MIR : met en MIRoir une arborescence (équivaut à /E plus /PURGE)
  • /SEC : copie des fichiers avec sécurité (équivaut à /COPY:DATS)

3. Conclusion

We've seen one use case, but Robocopy is a very versatile tool with lots of options! I encourage you to explore it in a test environment to validate the options before using them in production.

Thanks to this article from the Computer Tutorials box, you'll be able to take your first steps with Robocopy on Windows!

Resources :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *