Home > Tools > Use PSCP from Windows to copy files to network devices and Linux servers

Use PSCP from Windows to copy files to network devices and Linux servers

PuTTYI just had a question asking how I get files to/from network devices and Linux servers originating from a Windows machine. For this I use PSCP, which is a part of the PuTTY set of utilities. I use PSCP for two reasons:

  1. FTP is dead, stop using it!!! SCP, SFTP or other similar protocols should be used for transferring files! If your network devices are only setup for FTP or TFTP then get them configured correctly!! (The same goes for telnet, start using SSH!)
  2. Its command line driven. This makes it quick/easy to use and script with.

That said I would recommend downloading and installing the Windows installer version of PuTTY from the download page. This will insure you have all of the binaries and help file available in your start menu, this is not required for operation however. The PuTTY installer does not update the path environment so PSCP can be run from anywhere.  To use PSCP from anywhere in the command line you will either need to use the full path for the executable every time or add the correct path statement.

Here are the steps for adding the path with Win7 (pretty much the same for other versions of Windows):

  1. Go to the Start Menu and right-click on computer.
  2. Choose Properties.
  3. Click “Advanced System Settings”
  4. Click on the “Environmental Variables” button.
  5. In the “System Variables” section double-click on “Path”.
  6. Go to the end of the “Variable Value” blank and semi-colon and the path to where the PuTTY binaries are located. Here is the path statement I added for my 64-bit Win7 machine:
    ;C:\Program Files (x86)\PuTTY
    For a 32-bit Windows OS it would be:
    ;C:\Program Files\PuTTY
  7. Click OK out of all these screens and reboot.

You will now be able to use any of the PuTTY binaries (including PSCP) from the command line without using the full path.

Using PSCP is pretty easy. Just type PSCP without any options to see the usage.

Here is a sample upload via PSCP:

pscp test.file root@testhost:/tmp/

Here is a sample download via PSCP:

pscp root@testhost:/tmp/test.file .

If you’re not comfortable using the command line in Windows for file transfer then I would recommend WinSCP. But then if your working in network devices or Linux I would image you are OK with the command line.

Advertisements
Categories: Tools Tags:
  1. maybe
    February 5, 2011 at 19:12

    ftp is dead?

    • Ken Santema
      February 6, 2011 at 23:19

      It should be. But lazy developers, administrators, and other IT types keep using it.

  2. Manan
    July 29, 2011 at 05:30

    Just read the blog , felt good ..I developed somewhat the same thing yesterday itself (download access logs and various other monitoring logs from the various UNIx servers to the local system(Windows)..

  3. March 27, 2012 at 03:18

    What’s up, Just a notice that when I arrive at the homepage I am redirected to this comment page, I’m not sure why but thought you may like to know Mainly on the home page) Regards

  4. Abhinav
    April 26, 2017 at 04:48

    Hi Ken ,
    Is there any way i can troubleshoot the PSCP. I am trying to setup the password less ssh connection with a Linux server from windows machine. How ever , I am getting error connection refused,Is there any way i can generate the logs to check exact error.
    I have already imported the public key in the target system. Also logs generated from the -sshlogs option are below.

    Event Log: Writing new session log (SSH packets mode) to file: D:\ssh\ssh.txt
    Event Log: Server version: SSH-2.0-OpenSSH_5.3
    Event Log: We believe remote version has SSH-2 channel request bug
    Event Log: Using SSH protocol version 2
    Outgoing packet #0x0, type 20 / 0x14 (SSH2_MSG_KEXINIT)
    Incoming packet #0x0, type 20 / 0x14 (SSH2_MSG_KEXINIT)
    Event Log: Doing Diffie-Hellman group exchange
    Outgoing packet #0x1, type 34 / 0x22 (SSH2_MSG_KEX_DH_GEX_REQUEST)

    Incoming packet #0x1, type 31 / 0x1f (SSH2_MSG_KEX_DH_GEX_GROUP)
    Event Log: Doing Diffie-Hellman key exchange with hash SHA-256
    Outgoing packet #0x2, type 32 / 0x20 (SSH2_MSG_KEX_DH_GEX_INIT)
    Incoming packet #0x2, type 33 / 0x21 (SSH2_MSG_KEX_DH_GEX_REPLY)
    Event Log: Host key fingerprint is:
    Outgoing packet #0x3, type 21 / 0x15 (SSH2_MSG_NEWKEYS)
    Event Log: Initialised AES-128 SDCTR client->server encryption
    Event Log: Initialised HMAC-SHA-256 client->server MAC algorithm
    Incoming packet #0x3, type 21 / 0x15 (SSH2_MSG_NEWKEYS)
    Event Log: Initialised AES-128 SDCTR server->client encryption
    Event Log: Initialised HMAC-SHA-256 server->client MAC algorithm
    Outgoing packet #0x4, type 5 / 0x05 (SSH2_MSG_SERVICE_REQUEST)
    Incoming packet #0x4, type 6 / 0x06 (SSH2_MSG_SERVICE_ACCEPT)
    Event Log: Reading private key file “key.ppk”
    Outgoing packet #0x5, type 50 / 0x32 (SSH2_MSG_USERAUTH_REQUEST)
    Incoming packet #0x5, type 53 / 0x35 (SSH2_MSG_USERAUTH_BANNER)
    Incoming packet #0x6, type 51 / 0x33 (SSH2_MSG_USERAUTH_FAILURE)
    Outgoing packet #0x6, type 50 / 0x32 (SSH2_MSG_USERAUTH_REQUEST)
    Event Log: Offered public key
    Incoming packet #0x7, type 60 / 0x3c (SSH2_MSG_USERAUTH_PK_OK)
    Event Log: Offer of public key accepted
    Outgoing packet #0x7, type 50 / 0x32 (SSH2_MSG_USERAUTH_REQUEST)
    Event Log: Sent public key signature
    Event Log: Server unexpectedly closed network connection

  5. Abhinav
    April 26, 2017 at 09:25

    Below the the logs from the windows server trying to connect to Linux generated via -v option of pscp
    C:\Users\User>pscp -i “private.ppk” -P 22 -l User -v -sftp “file.txt” server.domain.com:/outboundpath/
    Looking up host “server.domain.com”
    Connecting to 199.199.199.127 port 22
    We claim version: SSH-2.0-PuTTY_Release_0.67
    Server version: SSH-2.0-OpenSSH_5.3
    We believe remote version has SSH-2 channel request bug
    Using SSH protocol version 2
    Doing Diffie-Hellman group exchange
    Doing Diffie-Hellman key exchange with hash SHA-256
    Host key fingerprint is:
    ssh-rsa 2048
    Initialised AES-128 SDCTR client->server encryption
    Initialised HMAC-SHA-256 client->server MAC algorithm
    Initialised AES-128 SDCTR server->client encryption
    Initialised HMAC-SHA-256 server->client MAC algorithm
    Reading private key file “private.ppk”
    Using username “connect”. LEGAL NOTICE

    You may commit a criminal offence if you act outside your
    authority in relation to this computer.

    Offered public key
    Offer of public key accepted
    Authenticating with public key “rsa-key-20170424”
    Sent public key signature
    Server unexpectedly closed network connection
    Fatal: Server unexpectedly closed network connection

  1. January 9, 2011 at 17:35
  2. January 25, 2011 at 21:43

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: