I am on machine A and want to pull a file from machine B.

A$ scp <myuserid>@hostB:<path of file in B> .

it says that:

scp: <path of file in B>: No such file or directory

But on machine B, this file exists in this path.

What is going wrong?

  • Is this the exact format of the command you ran? Or was there a file name after the ':'? – dtyler Oct 12 '11 at 16:20

You didn't specify any file: you have to add the file (with path) after the colon:

A$ scp <myuserid>@hostB:/absolutepath/file .


A$ scp <myuserid>@hostB:relativepath/file .

for a path relative to your home directory.

If you don't specify a different user (i.e., the user on A and B are the same) you don't need the @

A$ scp hostB:/path/file .
  • 2
    I fixed the formatting in the question, but maybe your answer is still valid. The problem might come from a confusion between absolute and relative (to home) paths. – Stéphane Gimenez Oct 12 '11 at 16:31
  • @StéphaneGimenez now that I see the edited answer I understand. It seemed a strange question :-) – Matteo Oct 12 '11 at 17:57
$ scp username@remoteip:remote_location_file /location/where/you/save

This only works when you copy file. if you want to copy a directory use

$ scp -r username@remoteip:remote_location_directory /location/where/you/save

Option you may use on your demand

-P port
Specifies the port to connect to on the remote host. Note that this option is written with a capital "P", because -p is already reserved for preserving the times and modes of the file in rcp.

Preserves modification times, access times, and modes from the original file.

Recursively copy entire directories.


Verbose mode. Causes scp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.

  • 1
    The OP asked for copying a file, not a directory. – countermode Nov 30 '16 at 13:16

use proper scp path

scp ssh://user@hostname/tmp/foo.txt .

You can specify either a file path that is relative to your home directory, or an absolute file path. For example, if foo.txt is in a directory called docs under your home directory and bar.txt is in /var/tmp, you can do

scp username@host.example.com:docs/foo.txt .
scp username@host.example.com:/var/tmp/bar.txt .

Note that if the file name contains characters that are special to the remote shell (typically whitespace or !"#$&'*;<>?[\]^`{|}~), you need to escape them for the remote shell in addition to escaping them for the local shell. For example, if the file is called foo bar.txt and is in your home directory:

scp username@host.example.com:'foo\ bar.txt' .

If you have difficulties with files containing punctuation characters, try using sftp instead of scp to transfer them. Or use an even more convenient method, if you can use FUSE: mount the remote machine's filesystem using sshfs, and then use ordinary file manipulation commands.

mkdir host.example.com
sshfs username@host.example.com:/ host.example.com
cp host.example.com/path/to/file .

One can SCP both way easily if one has the DMZ user and Password You are at your local machine: From DMZ to your local linux machine (pull). Means copy abc.text inside folder2 to your current logged-in PWD.

scp user@111111:folder1/folder2/abc.txt .

It will ask for password

thats all

Now you want to send a folder will subfolders and files from your local machine to DMZ:

usr@localmachine:~/abc/defs> scp -r folder/ usr@111111:vkrishna/docker/

again password will be asked

: is the root folder of the remote machine and vkrishna is a folder there & again docker subfolder. Locally defs folder has a folder called "folder" that we want to completely transfer.

Like /abc/defs/folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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