Copying files from one server to another is a frequently used task for any system administrator. There are several ways to copy files from one location to another.
You can use GUI to drag and drop files, use PowerShell copy command and also use robocopy command-line tool to perform the copying process.
If you want to copy a lot of files faster, you must use Robocopy to migrate files extremely fast. It is a very powerful tool that also prints a detailed report of the copy operation. With Robocopy, you can copy a single file, stripping all permissions, mirror an entire drive, and also delete anything in the destination that doesn’t match the source.
In this article, we will show you how to copy files from one location to another with Robocopy on Windows.
- Two systems running Windows server 16.
- An administrator password set on both systems.
Robocopy provides a rich set of features you can leverage to perform efficient and fast file copies and moves.
The basic syntax of the Robocopy command is as shown below:
robocopy SOURCE DESTINATION FILE OPTIONS
A brief explanation of each feature is shown below:
- /Z : It is used to copy files in restartable mode.
- /S : It is used to copy subdirectories without empty ones.
- /E : It is used to copy subdirectories with empty ones.
- /ZB : Uses restartable mode. If access is denied, this option uses Backup mode.
- /B : It is used to copy files in backup mode.
- /MT:16 : It is used to copy files in multithreaded mode. With this option, you can copy multiple files at the same time.
- /MOV : It is used to moves files, and deletes them from the source after they are copied.
- /MOVE : It is used to moves files and directories, and deletes them from the source after they are copied.
- /R:N : Specifies the number of retries on failed copies.
- /W:N : Specifies the wait time between retries, in seconds. The default value of N is 30.
- /TBD : Specifies that the system will wait for share names to be defined.
- /NP : Specifies that the progress of the copying operation will not be displayed.
- /V : Used to display verbose output, showing skipped files.
Copy Files and Directories on Local System
To copy all files in the specified directory without including sub-directories or the files stored in those, use the following command:
robocopy C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Desktop\
To copy all directories, sub-directories and all files stored in those directories, run the following command:
robocopy /S /E C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Desktop\
You can also specify the filenames and extensions that you want to copy which will skip other file names and extensions.
For example, if you want to copy only files with DLL extension, use the following command:
robocopy C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Desktop\ *.dll
Move Files and Directories on Local System
You can use the option /MOV to move files from one location to another.
robocopy /MOV C:\Users\Administrator\Desktop\Services C:\Users\Administrator\Downloads\
You can also use the option /MOVE to move files and directories from one location to another.
robocopy /MOVE /S /E C:\Users\Administrator\Desktop\System C:\Users\Administrator\Downloads\
Mirror a Directory
You can create an exact copy of the source folder in the specified destination folder using the option /MIR:
For example, create a mirror copy of the directory named Common with the following command:
robocopy /MIR C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Desktop\
The above command will also delete any extra files that are present in the destination and are not present in the source.
Copy Files with Specific Size
Robocopy allows you to specify the size of files that you want to copy.
For example, to copy all files that are lower than 2K, run the following command:
robocopy C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Documents\ /S /MAX:2000
To copy all files larger than 1K, run the following command:
robocopy C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Documents\ /S /MIN:1000
Copy File with Specific Attributes
All files and folders have different attributes that can be used for different purposes such as, listing owner, audit information, timestamps.
You can copy specific attributes with the robocopy command by specifying the /copy option.
A brief explanation of different attributes are shown below:
A : Used for attributes.
T : Used for time stamps.
D : Used to copy data properties.
S : Used for NTFS access control list.
O : Used for the owner information.
U : Used for Auditing information.
For example, to copy the owner information attributes, run the following command:
robocopy C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Desktop\ /copy:O
If you want to copy files with all attributes, run the following command:
robocopy C:\Users\Administrator\Downloads\Common C:\Users\Administrator\Desktop\ /copyall
Copy File From Local System To Remote System/Computer/Server
To copy files from the local system to the remote system, you will need to enable file sharing in the source device to allow Robocopy access to copy the files from the destination device.
You can share files by following the below steps:
1. Open File Explorer as shown below:
2. Right-click on the folder that you want to share and click on the Properties button as shown below:
3. Click on the Sharing tab. You should see the following page:
4. Click on the Share button. You should see the following page:
5. Select the Everyone group and click on the Add button. You should see the following page:
6. Select the Permission Level and click on the Share button. You should see the following page:
7. Click on the Done and Close button.
Note : Please remember the network path and IP address of the source computer.
Now lets login to the Destination computer and copy files from the Source computer using the robocopy command.
You can follow the below steps to copy files from the source computer to the destination computer.
1. Open Windows PowerShell from the Windows start menu:
2. Type the robocopy command with the IP address and path of the shared folder of the source computer as shown below:
robocopy //CLOUD-3D12HMD7F/Users/Administrator/Downloads/newshare C:\ /E /Z /ZB /R:5 /W:5 /TBD /NP /V /MT:16
In the above guide, you learned how to copy files and folders using the Robocopy command with several different examples.
You can now use this command to perform your day-to-day tasks. Feel free to ask any questions in the comments below!