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?
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?
You didn't specify any file: you have to add the file (with path) after the colon:
A$ scp <myuserid>@hostB:/absolutepath/file .
or
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 .
$ scp username@remoteip:remote_location_file /location/where/you/save
Just as a note: 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
We already saw the recursive option in the second command. This and a further selection of options you may use on your demand are listed from the man page:
-r
Recursively copy entire directories.
-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.
-p
Preserves modification times, access times, and modes from the original file.
-v
Verbose mode. Causes scp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.
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