- 10 PSCP Client Examples to Transfer Files from Windows to Linux
- 1. Download and Install pscp.exe
- 2. View All pscp Options
- 3. Copy from Windows to Linux (Local to Remote)
- 4. Copy from Linux to Windows (Remote to Local)
- 5. Quiet Copy (Without displaying Statistics)
- 6. Use PuTTY Session Name in PSCP
- 7. Preserve the Original Timestamp
- 8. PSCP Directory Recursively
- 9. Use Batch Mode for Non-Interactive Copy
- 10. Use a Particular Protocol
- If you enjoyed this article, you might also like..
- How To Use PSCP Command On Windows?
- Download Pscp
- Install Pscp
- Help and Options
- Download or Get File From Remote Server
- Download or Get Multiple Files From Remote Server
- Upload or Put File To Remote Server
- Upload or Put Files To Remote Server
- Download or Get Directories Recursively From Remote Server
- Upload or Put Directories Recursively To Remote Server
- Глава 5: Using PSCP to transfer files securely
- 5.1 Starting PSCP
- 5.2 PSCP Usage
- 5.2.1 The basics
- 5.2.1.1 user
- 5.2.1.2 host
- 5.2.1.3 source
- 5.2.1.4 target
- 5.2.2 Options
- 5.2.2.1 -ls list remote files
- 5.2.2.2 -p preserve file attributes
- 5.2.2.3 -q quiet, don’t show statistics
- 5.2.2.4 -r copies directories recursively
- 5.2.2.5 -batch avoid interactive prompts
- 5.2.2.6 -sftp , -scp force use of particular protocol
- 5.2.2.7 -no-sanitise-stderr : control error message sanitisation
- 5.2.3 Return value
- 5.2.4 Using public key authentication with PSCP
10 PSCP Client Examples to Transfer Files from Windows to Linux
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.
3. Copy from Windows to Linux (Local to Remote)
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.
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:
If you don’t specify the “:” after the ip-address, it will give the following error message:
4. Copy from Linux to Windows (Remote to Local)
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.
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:
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.
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:
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.
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.
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).
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):
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:
If you try to do -scp on a newer Linux server that doesn’t support SSH-1, you’ll get the following error message:
If you enjoyed this article, you might also like..
100 Best Freeware for Windows — Free eBook
You’ve already spent a lot to purchase your laptop that runs on Windows.
Don’t waste any more purchasing commercial software for your Windows systems when there are several very good free alternatives available.
There are a total of 100 freeware programs listed in this eBook, each with a brief description, download link, and review link.
Comments on this entry are closed.
Thanks for your post, Ramesh! Helped me a lot!
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
Источник
How To Use PSCP Command On Windows?
pscp command is an SCP protocol implementation where we can transfer and copy files and folders securely over a network with the SSH connection. In this tutorial, we will learn how to install and use pscp tool on Windows operating system.
Download Pscp
pscp command can be downloaded from the following link. There are different installation types. pscp can be installed in standalone or with the putty installer package. I prefer Putty installation package where path environment configuration also done automatically.
Download Pscp
As we can see there is 32 and 64 bit versions. I will use 64 bit because my Windows is 64 bit.
Install Pscp
We will install the downloaded putty 64 bit msi package regular Windows Next->Next style like below.
Install Pscp
Help and Options
If we need to list all available options and help information we can just issue pscp command to the command line or MSDOS like below.
Help and Options
We can see that the usage or syntax of the pscp command is provided the start of the help information. Also, all available options are printed after the Options: part.
Download or Get File From Remote Server
We will start with a simple example where we will download or get a single file from a remote server or system. As stated previously we will use SSH protocol for connection and transfer. We will just provide the remote system user name, IP address or hostname and the file with its absolute path. We will also provide the file name we want to save locally.
We can see that for the first time we will connect a server we need to approve the remote server puıblic key. Then we provide the password for the user ismail . After we authenticated successfully the transfer of the file is completed successfully.
Download or Get Multiple Files From Remote Server
In the previous example, we have downloaded or got a single file from the remote server. We can also download and get multiple files from a remote system according to their path or file extension.
In this example we will download all gzipped file with the gz extension those resides /home/ismail . . means we will save to the current working directory.
Download or Get Multiple Files From Remote Server
Upload or Put File To Remote Server
We can also upload or put given file to the remote SSH server with the pscp command. We will first provide the file name and then provide the remote system user name, IP address or Host name and the path we want to put.
Upload or Put File To Remote Server
Upload or Put Files To Remote Server
We can also put multiple files to the remote server with pscp command. We will provide the file names before the remote server, user information. In this example, we will copy local files pass.txt , config.sys to the remote server.
Upload or Put Files To Remote Server
Download or Get Directories Recursively From Remote Server
If we want to get remote directories and download local we need to use recursive options which is -r .
Upload or Put Directories Recursively To Remote Server
We can also send or upload local directories to the remote server. We will again use the -r option.
We will put local directory name Downloads to the remote server 192.168.142.144 and folder /home/ismail/Downloads
Источник
Глава 5: Using PSCP to transfer files securely
PSCP, the PuTTY Secure Copy client, is a tool for transferring files securely between computers using an SSH connection.
If you have an SSH-2 server, you might prefer PSFTP (see chapter 6) for interactive use. PSFTP does not in general work with SSH-1 servers, however.
5.1 Starting PSCP
PSCP is a command line application. This means that you cannot just double-click on its icon to run it and instead you have to bring up a console window. With Windows 95, 98, and ME, this is called an «MS-DOS Prompt» and with Windows NT, 2000, and XP, it is called a «Command Prompt». It should be available from the Programs section of your Start Menu.
To start PSCP it will need either to be on your PATH or in your current directory. To add the directory containing PSCP to your PATH environment variable, type into the console window:
This will only work for the lifetime of that particular console window. To set your PATH more permanently on Windows NT, 2000, and XP, use the Environment tab of the System Control Panel. On Windows 95, 98, and ME, you will need to edit your AUTOEXEC.BAT to include a set command like the one above.
5.2 PSCP Usage
Once you’ve got a console window to type into, you can just type pscp on its own to bring up a usage message. This tells you the version of PSCP you’re using, and gives you a brief summary of how to use PSCP:
(PSCP’s interface is much like the Unix scp command, if you’re familiar with that.)
5.2.1 The basics
To receive (a) file(s) from a remote server:
So to copy the file /etc/hosts from the server example.com as user fred to the file c:\temp\example-hosts.txt , you would type:
To send (a) file(s) to a remote server:
So to copy the local file c:\documents\foo.txt to the server example.com as user fred to the file /tmp/foo you would type:
You can use wildcards to transfer multiple files in either direction, like this:
However, in the second case (using a wildcard for multiple remote files) you may see a warning saying something like «warning: remote host tried to write to a file called « terminal.c » when we requested a file called « *.c ». If this is a wildcard, consider upgrading to SSH-2 or using the « -unsafe » option. Renaming of this file has been disallowed».
This is due to a fundamental insecurity in the old-style SCP protocol: the client sends the wildcard string ( *.c ) to the server, and the server sends back a sequence of file names that match the wildcard pattern. However, there is nothing to stop the server sending back a different pattern and writing over one of your other files: if you request *.c , the server might send back the file name AUTOEXEC.BAT and install a virus for you. Since the wildcard matching rules are decided by the server, the client cannot reliably verify that the filenames sent back match the pattern.
PSCP will attempt to use the newer SFTP protocol (part of SSH-2) where possible, which does not suffer from this security flaw. If you are talking to an SSH-2 server which supports SFTP, you will never see this warning. (You can force use of the SFTP protocol, if available, with -sftp — see section 5.2.2.6.)
If you really need to use a server-side wildcard with an SSH-1 server, you can use the -unsafe command line option with PSCP:
This will suppress the warning message and the file transfer will happen. However, you should be aware that by using this option you are giving the server the ability to write to any file in the target directory, so you should only use this option if you trust the server administrator not to be malicious (and not to let the server machine be cracked by malicious people). Alternatively, do any such download in a newly created empty directory. (Even in «unsafe» mode, PSCP will still protect you against the server trying to get out of that directory using pathnames including « .. ».)
5.2.1.1 user
The login name on the remote server. If this is omitted, and host is a PuTTY saved session, PSCP will use any username specified by that saved session. Otherwise, PSCP will attempt to use the local Windows username.
5.2.1.2 host
The name of the remote server, or the name of an existing PuTTY saved session. In the latter case, the session’s settings for hostname, port number, cipher type and username will be used.
5.2.1.3 source
One or more source files. Wildcards are allowed. The syntax of wildcards depends on the system to which they apply, so if you are copying from a Windows system to a UNIX system, you should use Windows wildcard syntax (e.g. *.* ), but if you are copying from a UNIX system to a Windows system, you would use the wildcard syntax allowed by your UNIX shell (e.g. * ).
If the source is a remote server and you do not specify a full pathname (in UNIX, a pathname beginning with a / (slash) character), what you specify as a source will be interpreted relative to your home directory on the remote server.
5.2.1.4 target
The filename or directory to put the file(s). When copying from a remote server to a local host, you may wish simply to place the file(s) in the current directory. To do this, you should specify a target of . . For example:
. would copy /home/tom/.emacs on the remote server to the current directory.
As with the source parameter, if the target is on a remote server and is not a full path name, it is interpreted relative to your home directory on the remote server.
5.2.2 Options
PSCP accepts all the general command line options supported by the PuTTY tools, except the ones which make no sense in a file transfer utility. See section 3.8.3 for a description of these options. (The ones not supported by PSCP are clearly marked.)
PSCP also supports some of its own options. The following sections describe PSCP’s specific command-line options.
5.2.2.1 -ls list remote files
If the -ls option is given, no files are transferred; instead, remote files are listed. Only a hostname specification and optional remote file specification need be given. For example:
The SCP protocol does not contain within itself a means of listing files. If SCP is in use, this option therefore assumes that the server responds appropriately to the command ls -la ; this may not work with all servers.
If SFTP is in use, this option should work with all servers.
5.2.2.2 -p preserve file attributes
By default, files copied with PSCP are timestamped with the date and time they were copied. The -p option preserves the original timestamp on copied files.
5.2.2.3 -q quiet, don’t show statistics
By default, PSCP displays a meter displaying the progress of the current transfer:
The fields in this display are (from left to right), filename, size (in kilobytes) of file transferred so far, estimate of how fast the file is being transferred (in kilobytes per second), estimated time that the transfer will be complete, and percentage of the file so far transferred. The -q option to PSCP suppresses the printing of these statistics.
5.2.2.4 -r copies directories recursively
By default, PSCP will only copy files. Any directories you specify to copy will be skipped, as will their contents. The -r option tells PSCP to descend into any directories you specify, and to copy them and their contents. This allows you to use PSCP to transfer whole directory structures between machines.
5.2.2.5 -batch avoid interactive prompts
If you use the -batch option, PSCP will never give an interactive prompt while establishing the connection. If the server’s host key is invalid, for example (see section 2.2), then the connection will simply be abandoned instead of asking you what to do next.
This may help PSCP’s behaviour when it is used in automated scripts: using -batch , if something goes wrong at connection time, the batch job will fail rather than hang.
5.2.2.6 -sftp , -scp force use of particular protocol
As mentioned in section 5.2.1, there are two different file transfer protocols in use with SSH. Despite its name, PSCP (like many other ostensible scp clients) can use either of these protocols.
The older SCP protocol does not have a written specification and leaves a lot of detail to the server platform. Wildcards are expanded on the server. The simple design means that any wildcard specification supported by the server platform (such as brace expansion) can be used, but also leads to interoperability issues such as with filename quoting (for instance, where filenames contain spaces), and also the security issue described in section 5.2.1.
The newer SFTP protocol, which is usually associated with SSH-2 servers, is specified in a more platform independent way, and leaves issues such as wildcard syntax up to the client. (PuTTY’s SFTP wildcard syntax is described in section 6.2.2.) This makes it more consistent across platforms, more suitable for scripting and automation, and avoids security issues with wildcard matching.
Normally PSCP will attempt to use the SFTP protocol, and only fall back to the SCP protocol if SFTP is not available on the server.
The -scp option forces PSCP to use the SCP protocol or quit.
The -sftp option forces PSCP to use the SFTP protocol or quit. When this option is specified, PSCP looks harder for an SFTP server, which may allow use of SFTP with SSH-1 depending on server setup.
5.2.2.7 -no-sanitise-stderr : control error message sanitisation
The -no-sanitise-stderr option will cause PSCP to pass through the server’s standard-error stream literally, without stripping control characters from it first. This might be useful if the server were sending coloured error messages, but it also gives the server the ability to have unexpected effects on your terminal display. For more discussion, see section 7.2.3.5.
5.2.3 Return value
PSCP returns an ERRORLEVEL of zero (success) only if the files were correctly transferred. You can test for this in a batch file, using code such as this:
5.2.4 Using public key authentication with PSCP
Like PuTTY, PSCP can authenticate using a public key instead of a password. There are three ways you can do this.
Firstly, PSCP can use PuTTY saved sessions in place of hostnames (see section 5.2.1.2). So you would do this:
- Run PuTTY, and create a PuTTY saved session (see section 4.1.2) which specifies your private key file (see section 4.23.8). You will probably also want to specify a username to log in as (see section 4.15.1).
- In PSCP, you can now use the name of the session instead of a hostname: type pscp sessionname:file localfile , where sessionname is replaced by the name of your saved session.
Secondly, you can supply the name of a private key file on the command line, with the -i option. See section 3.8.3.18 for more information.
Thirdly, PSCP will attempt to authenticate using Pageant if Pageant is running (see chapter 9). So you would do this:
- Ensure Pageant is running, and has your private key stored in it.
- Specify a user and host name to PSCP as normal. PSCP will automatically detect Pageant and try to use the keys within it.
For more general information on public-key authentication, see chapter 8.
Источник