208

I am having trouble copying files from a remote server using SSH. Using PuTTY I log in to the server using SSH. Once I find the file I would like to copy over to my computer, I use the command:

scp [email protected]:/dir/of/file.txt \local\dir\

It looks like it was successful, but it only ends up creating a new folder labeled 'localdir' in the remote directory /dir/of/.

How can I copy the file to my local computer over SSH?

4
  • 1
    Your question is not clear on this: are you running scp on your local computer or inside the remote shell via SSH? May 31, 2015 at 3:17
  • Inside the remote shell via SSH, I believe.
    – Vincent
    May 31, 2015 at 4:02
  • 1
    I wanted to pop this in as I can't make it an answer... a program called FileZilla allows you to connect to your ssh and exchange files between your server and local device.
    – Lukali
    Jul 28, 2021 at 11:02
  • you can install Git and enter scp username@host:path_to_file path_in_the_local_machine This will ask for your password in the remote machine. Sep 11, 2021 at 20:02

5 Answers 5

380

It depends on what your local OS is.

If your local OS is Unix-like, then try:

scp username@remoteHost:/remote/dir/file.txt /local/dir/

If your local OS is Windows ,then you should use pscp.exe utility. For example, below command will download file.txt from remote to D: disk of local machine.

pscp.exe username@remoteHost:/remote/dir/file.txt d:\

It seems your Local OS is Unix, so try the former one.


For those who don't know what pscp.exe is and don't know where it is, you can always go to putty official website to download it. And then open a CMD prompt, go to the pscp.exe directory where you put it. Then execute the command as provided above

EDIT

if you are using Windows OS above Windows 10, then you can use scp directly from its terminal, just like how Unix-like OS does. Thanks to @gijswijs @jaunt @icanfathom

8
  • My local OS is Windows. I downloaded the pscp.exe from the putty website. I tried opening it up and nothing came up. Also, I tried the command you listed above and was given: pscp.exe comman not found. Also tried it without the .exe and resulted in the same error.
    – Vincent
    May 31, 2015 at 3:57
  • 2
    Open a CMD prompt, and go to the pscp.exe directory where you put it. Then execute the command as provided above.
    – mainframer
    May 31, 2015 at 4:01
  • 1
    using scp on a mac has to be provided ./ parameter to signify that the file has to be downloaded in the current folder on mac machine. Jul 2, 2018 at 11:11
  • 2
    With Windows Subsystem for Linux (WSL, basically Ubuntu on Windows) you can now also open up Bash if your Local OS is Windows, and just use scp. Pro-tip: you can access your Windows file system from WSL. It's under /mnt/c. So you can do something like this: scp username@remoteHost:/remote/dir/file.txt /mnt/c
    – gijswijs
    Apr 25, 2019 at 3:42
  • 4
    As of the 2018 Autumn update, Windows 10 now comes with OpenSSH and is on PATH. This means you can use the scp command on Windows 10, too.
    – jaunt
    Sep 23, 2019 at 20:45
41

Your question is a bit confusing, but I am assuming - you are first doing 'ssh' to find out which files or rather specifically directories are there and then again on your local computer, you are trying to scp 'all' files in that directory to local path. you should simply do scp -r.

So here in your case it'd be something like

local> scp -r [email protected]:/path/to/dir local/path 

If youare using some other executable that provides 'scp like functionality', refer to it's manual for recursively copying files.

25

You need to name the file in both directory paths.

scp [email protected]:/dir/of/file.txt \local\dir\file.txt
7
  • 3
    I don't believe that's correct. If the destination target is a directory, it will place the file there with the same filename as the source. May 31, 2015 at 3:21
  • @WilliamPrice I think it depends on the local OS
    – 0yeoj
    May 31, 2015 at 3:26
  • 1
    @0yeoj For my edification, which local OS is that? I dual boot Fedora and Win8.1 and verified that specifying just the target directory works with both the Linux version of scp and the Putty-provided pscp executables. May 31, 2015 at 3:39
  • @WilliamPrice, try looking at mainframer 's answer your probably check, and you are correct about If the destination target is a directory, it will place the file there with the same filename as the source.
    – 0yeoj
    May 31, 2015 at 3:58
  • It seems I was indeed wrong about this.
    – Andy
    May 31, 2015 at 4:04
9

Make sure the scp command is available on both sides - both on the client and on the server.

BOTH Server and Client, otherwise you will encounter this kind of (weird)error message on your client: scp: command not found or something similar even though though you have it all configured locally.

3

that scp command must be issued on the local command-line, for putty the command is pscp.

C:\something> pscp [email protected]:/dir/of/file.txt \local\dir\
3
  • I downloaded the pscp.exe from putty and tried to open it but nothing came up. Then I tried the command in the putty.exe application and was given an error: pscp command not found.
    – Vincent
    May 31, 2015 at 3:59
  • 2
    it has to be installed in your path given that you seem unaware of that , you might find filezilla easier to use than scp.
    – Jasen
    May 31, 2015 at 4:05
  • Filezilla is super simple to work with. I was able to setup FileZilla and connect to a Raspberry pi using the SSH credentials. Jan 13, 2022 at 15:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.