One of the best SSH client utility to connect from Linux to Windows is PuTTY.
We explained in detail on how to use PuTTY in our earlier article.
pscp.exec is PuTTY SCP Client, which is used to transfer file securely from Windows to Linux using SSH connections.
One advantage of PSCP is that it will work with even the older version of SSH servers (i.e SSH-1 servers).
This article provides various practical examples on how to use pscp.exe on Windows.
1. Download and Install pscp.exe
From the PuTTY download page, download the pscp.exec (PuTTY SCP Client) file.
Just like putty.exe, pscp.exe is also a single executable file, which you don’t need to install. This makes it easy to carry it on your USB drive.
Put the pscp.exe file in any one of the directories mentioned in your PATH variable. This way, you can execute pscp from any directory location.
For example, put the pscp.exe file in the “C:\Windows\System32” directory.
2. View All pscp Options
Next, launch the command prompt on Windows using one of the following methods:
- Click on Windows start button, type “cmd” in the “search programs and files” text box, and press Enter
- Click on Windows start button -> Click on “Accessories” -> Click on “Command Prompt” program.
Type pscp, which will display all available options for pscp.exe file as shown below.
C:\> pscp PuTTY Secure Copy client Release 0.63 Usage: pscp [options] [user@]host:source target pscp [options] source [source...] [user@]host:target pscp [options] -ls [user@]host:filespec Options: -V print version information and exit -pgpfp print PGP key fingerprints and exit -p preserve file attributes -q quiet, don't show statistics -r copy directories recursively -v show verbose messages -load sessname Load settings from saved session -P port connect to specified port -l user connect with specified username -pw passw login with specified password -1 -2 force use of particular SSH protocol version -4 -6 force use of IPv4 or IPv6 -C enable compression -i key private key file for authentication -noagent disable use of Pageant -agent enable use of Pageant -batch disable all interactive prompts -unsafe allow server-side wildcards (DANGEROUS) -sftp force use of SFTP protocol -scp force use of SCP protocol
3. Copy from Windows to Linux (Local to Remote)
Syntax:
pscp local-file-name username@remote-host:/directory/name
The following example transfers the file “C:\Users\ramesh\Downloads\vpn-setup.png” from local Windows machine to remote Linux machine with ip-address 192.168.101.1
On the remote Linux machine, it will connect using the username “ramesh”. It will prompt for the password, and then start the transfer.
C:\> pscp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1: ramesh@192.168.101.1's password: vpn-setup.png | 16 kB | 16.4 kB/s | ETA: 00:00:00 | 100%
In the above example, since we’ve given “:” at the end of the ip-address and no other directory name after that, it will copy the vpn-setup.png to the home directory of ramesh username on the remote Linux server.
If you want to copy it to a different directory on the remote server. For example, to /tmp, do the following:
C:\> pscp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1:/tmp
If you don’t specify the “:” after the ip-address, it will give the following error message:
C:\> pscp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1 Local to local copy not supported
4. Copy from Linux to Windows (Remote to Local)
Syntax:
pscp username@remote-host:/directory-name/file-name C:/local/directory-name
The following example transfer the file /home/ramesh/project.tar from the remote Linux server with ip-address 192.168.101.1 to the local Windows server. This copies the files to C:\Users\ramesh\Downloads directory on the local Windows laptop.
C:\> pscp ramesh@192.168.101.1:project.tar C:\Users\ramesh\Downloads ramesh@192.168.101.1's password: project.tar | 42330 kB | 1924.1 kB/s | ETA: 00:00:00 | 100%
5. Quiet Copy (Without displaying Statistics)
If you don’t want the progress-bar statistics to be displayed while it doing the copy (and after it copied the file), pass -q option (which stands for quiet) as shown below:
C:\> pscp -q "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1: ramesh@192.168.101.1's password:
6. Use PuTTY Session Name in PSCP
If you are already using PuTTY, and have sessions stored, you don’t need to specify the username and ip-address in the pscp command. Instead you can just specify the PuTTY session name, and it will get the username/password from the PuTTY session automatically.
In the following example, it is using the PuTTY session dev-db, which already has the ip-address 192.168.101.1 and ramesh username associated with it. It will just use that to connect and transfer file automatically.
C:\> pscp dev-db:project.tar C:\Users\ramesh\Downloads ramesh@192.168.101.1's password: project.tar | 17504 kB | 1346.5 kB/s | ETA: 00:00:18 | 41%^C
7. Preserve the Original Timestamp
When you copy files using pscp, by default, the transferred files will have the current date and time. You can keep the original file’s timestamp by using -p option, which will preserve the file’s attributes as shown below:
C:\> pscp -p "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1:
8. PSCP Directory Recursively
By default PuTTY will transfer only files. But when you specify a directory name, it will give the following error message.
C:\> pscp ramesh@192.168.101.1:Downloads C:\Users\ramesh\Downloads ramesh@192.168.101.1's password: pscp: Downloads: is a directory
To copy directory, you should also use -r to indicate PSCP to copy that particular directory along with all its content as shown below.
The following example will copy the content of /home/ramesh/Downloads from remote Linux server to C:\Users\ramesh\Downloads on the local server.
C:\> pscp -r ramesh@192.168.101.1:Downloads C:\Users\ramesh\Downloads ramesh@192.168.101.1's password: tunnel.sh | 0 kB | 0.6 kB/s | ETA: 00:00:00 | 100% backup.sh | 1 kB | 1.1 kB/s | ETA: 00:00:00 | 100% oracle.sh | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100% ..
9. Use Batch Mode for Non-Interactive Copy
You can combine the key-based authentication (instead of password based) along with the -batch option to do non-interactive pscp between Windows and Linux servers. This is very helpful when you want to schedule some background tasks on your Windows machine to perform some routine file transfer jobs.
The following example will run the pscp in non-interactive mode by using the dev-db PuTTY session (which you should’ve already setup using key-based authentication).
C:\> pscp -batch dev-db:project.tar C:\Users\ramesh\Downloads
Please note that if pscp cannot authenticate with the given session, it will not give any error in the batch mode, it will just disconnect quietly. So, you should manually test this to make sure it is doing exactly what you are expecting it to do.
10. Use a Particular Protocol
SSH-2 is typically used with SFTP and SSH-1 is typically used with SCP.
However PSCP is smart. By default, it uses SSH-2 protocol to connect, when it fails, it then uses SSH-1 protocol.
You can force pscp to use either SSH-1 (scp) or SSH-2 (sftp) as shown below:
So, giving “-sftp” is optional. The following both are exactly the same (when SFTP is supposed on the destination Linux server):
C:\> pscp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1: C:\> pscp -sftp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1:
If you want to force pscp to use SSH-1 only (you’ll do this typically on a older UNIX server that doesn’t support SSH-2), do the following:
C:\> pscp -scp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1:
If you try to do -scp on a newer Linux server that doesn’t support SSH-1, you’ll get the following error message:
C:\> pscp -scp "C:\Users\ramesh\Downloads\vpn-setup.png" ramesh@192.168.101.1: ramesh@192.168.101.1's password: scp: warning: Executing scp1. scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH). Fatal: Received unexpected end-of-file from server
Comments on this entry are closed.
Thanks for your post, Ramesh! Helped me a lot!
Boris
How can I enter password in same command line where I am writing command for transferring file, so I don’t have to be prompted, lets say for automated purpose.
with the option -pw
The command line docs show
-pw
for automated login.
Getting error while running
C:\Users\manish.mishra\Downloads>pscp 101.txt root@ip:/tmp/manish
Fatal: Network error: Cannot assign requested address
Very nice article, if we setup pscp.exe then we can download by following way as well, I hope this will help someone.
pscp.exe -r root@hostname:/var/www/html d:/adk // this will download the complete folder html in adk
Thanks. Saved a lot of time.
Fatal: Network error: Software caused connection abort
what can be the issue sir