Close

pscp – File Transfer with PuTTY

pscp – PuTTY Secure Copy

The PuTTY tool suite allows to perform file transfers via SSH, avoiding the need to have a separate SFTP client. It’s not the most practical way, but comes very handy in some situations.

C:\LocalPrograms\Putty>pscp

PuTTY Secure Copy client
Release 0.63
Usage: pscp [options] [user@]host:source target
       pscp [options] 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

Example: Uploading a file or a directory tree, user login via certificate

Copies the c:\sourcefolder, including sub-directories, to the /root directory on the server, using an SFTP connection authenticated by the root account SSL certificate.

Since we want to use an existing SSL certificate, we need to have a profile named “myserver.xyz.profile” (-load) existing in the Putty configuration. This profile can be created using the classic putty.exe application.

The profile defines all parameters describing the connection: the protocol (SSH, port 22), potential proxies, preferred SSH version (‘2 only’ mostly), the key file (“Connection/SSH/Auth/Private key file for authentication”) and other things.

-pw specifies the password of the private key file. Be aware of command line historisation when typing passwords as part of a command.

C:\LocalPrograms\Putty> pscp -v   -load myserver.xyz.profile -pw password     -r      c:\sourcefolder  root@myserver.xyz:/root
                          (verbose)     (load profile)       (key password) (recursive)   (source)         (target)


Looking up host "myserver.xyz"
Connecting to 1.1.1.1 port 8012
We claim version: SSH-2.0-PuTTY_Release_0.63
Server version: SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze5
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 00:00:00:00:00:00:00:00:00:00
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Reading private key file "C:\topsecret\ssl_private_key_for_root.bin"
Using username "root".
Offered public key
Offer of public key accepted
Authenticating with public key "rsa-key-1111"
Sent public key signature
Access granted
Opening session as main channel
Remote debug message: Your host '1.1.1.1' is not permitted to use this key for login.
Opened main channel
Started a shell/command
Using SFTP
Connected to myserver.xyz
Entering directory: sourcefolder
Sending file 1.jpg, size=180372
1.jpg                | 176 kB  | 176.1 kB/s | ETA: 00:00:00 | 100%
Sending file 2.jpg, size=1579891
2.jpg                | 1542 kB | 514.3 kB/s | ETA: 00:00:00 | 100%
:
:

Example: List files on server (ls)

<C:\LocalPrograms\Putty> pscp -v -load myserver.xyz.profile -pw mykeypassword -ls root@myserver.xyz:/root

Looking up host "myserver.xyz"
Connecting to 1.1.1.1 port 8024
We claim version: SSH-2.0-PuTTY_Release_0.63
Server version: SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze5
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
:
:
Opened main channel
Started a shell/command
Using SFTP
Connected to myserver.xyz
Listing directory /root
drwx------   12 root     root         4096 Aug 26 11:35 .
drwxr-xr-x   22 root     root         4096 Jan 27  2012 ..
:
:
-rw-r--r--    1 root     root        65650 Nov 13  2012 J.tar.gz
-rw-r--r--    1 root     root         4276 Jan  2  2012 README.txt
-rw-r--r--    1 root     root     20071146 Dec 20  2011 p.tar.gz
Sent EOF message
Server sent command exit status 0
Disconnected: All channels closed

Example: Download a file from server directory to current local directory

Note that the . at the end of the command is not a typo, but indicates the current directory as destination.

C:\LocalPrograms\Putty> pscp -v -load myserver.xyz.profile -pw secretpassword -r  root@myserver.xyz:/home/tasha/lotoffiles/*.*  .

Looking up host "myserver.xyz"
Connecting to 1.1.1.1 port 8010
We claim version: SSH-2.0-PuTTY_Release_0.63
Server version: SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze5
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
:
:
Opened main channel
Started a shell/command
Using SFTP
Connected to myserver.xyz
file1           | 0 kB |   0.8 kB/s | ETA: 00:00:00 | 100%
fiel2           | 1 kB |   1.4 kB/s | ETA: 00:00:00 | 100%
file3           | 1 kB |   1.4 kB/s | ETA: 00:00:00 | 100%
Sent EOF message
Server sent command exit status 0
Disconnected: All channels closed

Wiki: http://tech.lab.carl.pro/tipbase/putty_filetransfer

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close