How to download a file from my server using SSH (using PuTTY on Windows)

SobieSki picture SobieSki · Mar 2, 2014 · Viewed 284.8k times · Source

When I try downloading a file from my server onto my computer, it actually downloads the file onto the server.

(Note I am already SSH'd into my server before typing this command. I've watched tutorials on YouTube and people are using their terminal without SSHing into any particular server, however I don't think I can do this with PuTTY on Windows?)

scp -r -P2222 [email protected]:/home2/kwazy/www/utrecht-connected.nl ~/Desktop/

The problem is that I am specifying the location to download the file as only ~/Desktop/

This creates a folder called Desktop in my server, instead of copying the files onto my local desktop.

I'd greatly appreciate any assistance.


Update:

I am able to use this command on Linux.

I have successfully download the folder onto my desktop:

I still need insight onto how I can do this on a Windows machine.

Answer

Martin Prikryl picture Martin Prikryl · Mar 3, 2015

There's no way to initiate a file transfer back to/from local Windows from a SSH session opened in PuTTY window.

Though PuTTY supports connection-sharing.

While you still need to run a compatible file transfer client (pscp or psftp), no new login is required, it automatically (if enabled) makes use of an existing PuTTY session.

To enable the sharing see:
Sharing an SSH connection between PuTTY tools.


Even without connection-sharing, you can still use the psftp or pscp from Windows command line.

See How to use PSCP to copy file from Unix machine to Windows machine ...?

Note that the scp is OpenSSH program. It's primarily *nix program, but you can run it via Windows Subsystem for Linux or get a Windows build from Win32-OpenSSH (it is already built-in in the latest versions of Windows 10).


If you really want to download the files to a local desktop, you have to specify a target path as %USERPROFILE%\Desktop (what typically resolves to a path like C:\Users\username\Desktop).


Alternative way is to use WinSCP, a GUI SFTP/SCP client. While you browse the remote site, you can anytime open SSH terminal to the same site using Open in PuTTY command.
See Opening Session in PuTTY.

With an additional setup, you can even make PuTTY automatically navigate to the same directory you are browsing with WinSCP.
See Opening PuTTY in the same directory.

(I'm the author of WinSCP)