It is not always that you will need to copy a file from Windows to Linux or vice versa. But at times when you are automating things or trying to achieve some copy functionality using a script, it is good to have a utility to do that. Here is where pscp comes into play. Using pscp you can copy the file to/from windows and Linux. In this guide, I will go through the steps of doing the transfer files between Windows & Linux Machine using Command Line & PowerShell and explain the possible errors and solutions for them.
WINDOWS TO LINUX
1. Download pscp.exe from here
2. copy the pscp.exe executable to the system32 directory of your windows machine. This folder normally exists in C:\Windows\System32 path.
3. Open PowerShell and use the following command to verify if pscp is accessible from the path.
4. Use the following format to copy the file to the Linux box.
pscp F:\temp\*.csv email@example.com:/tmp/target_folder
- pscp – It will invoke the PSCP command line utility to initiate copy.
- F:\temp\*.csv – This is the actual file(s) path which you need to copy to Linux machine.
- user – It is your user account on the target Linux machine
- 192.168.0.3 – Here you can give IP/Hostname of Linux Machine
- /tmp/target_folder – It is the Target Directory in which files will be copied.
Possible Errors You May Get:
The server’s host key is not cached in the registry
This error occurs when you are copying to a Linux machine you never connected or copying first time. To resolve this, you need to login once on the Linux machine using Putty. While logging in first time, it will ask you to add the Host to cache. Just click on Yes and your problem will be resolved.
LINUX TO WINDOWS
You can use pscp to copy files from Linux to windows. use the following command format for the same.
pscp firstname.lastname@example.org:/tmp/target_folder/*.CSV F:\temp\
The above command will copy the file in Linux from the specified path to the Windows desktop. In this way you can easily transfer files between Windows & Linux Machine using Command Line & PowerShell. Please let us know if you have any suggestion in the comment section below.
You’ll also like:
- Windows Command Line Utilities Every Professional Should Know
- An Introduction to VMware PowerCLI
- Disable Clipboard Redirection Multiple Servers PowerShell