235
votes
Accepted
How to copy all files from a directory to a remote directory using scp?
scp has the -r argument. So, try using:
$ scp -r ~/local_dir [email protected]:/var/www/html/target_dir
The -r argument works just like the -r arg in cp, it will transfer your entire folder and all the ...
120
votes
Why is scp so slow and how to make it faster?
You could use rsync (over ssh), which uses a single connection to transfer all the source files.
rsync -avP cap_* user@host:dir
If you don't have rsync (and why not!?) you can use tar with ssh like ...
66
votes
How to copy all files from a directory to a remote directory using scp?
If your goal is to transfer all files from local_dir the * wildcard does the trick:
$ scp ~/local_dir/* [email protected]:/var/www/html/target_dir
The -r option means "recursively", so you must write it ...
49
votes
Accepted
Copying files with certain extensions with scp
Just replace it with:
scp [email protected]:'/folder/*.{jpg,png}' .
Please note the pair of single quotes. In your case, your local shell is evaluating the expression, turning it really into:
...
45
votes
Is scp unsafe? Should it be replaced with sftp?
It's marginally "unsafe"
It was marginally "unsafe" before the addition of scp -T in OpenSSH 8.0 and it still is marginally "unsafe" when using scp -r.
Like other answers have stated, claims that ...
43
votes
Use scp to transfer a file from local directory X to remote directory Y
I provide two methods of up/down load file between remote and local machine(I use Mac air):
In this case, I want to up/down 11.jpeg between local and remote:
Copy files on service to local dir: You ...
40
votes
How can I download a file from a host I can only SSH to through another host?
If you have a recent OpenSSH (8.0) locally, you can use the -J (jump) switch:
scp -J user@intermediate user@target:/path
With older versions (but at least 7.3), you can use ProxyJump directive, ...
39
votes
how to append public keys to remote host instead of copy it
You can also use ssh-copy-id, which is a tool to do exactly what you want: add one or more keys to the authorized_keys of a remote system.
38
votes
Accepted
How can I download a file from a host I can only SSH to through another host?
The previous answers mention how to use the ProxyJump directive (added in OpenSSH 7.3) to connect through an intermediate server (usually referred to as the bastion host), but mention it just as a ...
35
votes
Sending files over Samba with command line
curl supports the smb v1 protocol since v7.40:
curl --upload-file /path/to/file.ext -u 'DOMAIN\Username' smb://172.16.17.52/ShareName/
SMB v1 is not available by default in Windows anymore so this ...
33
votes
Accepted
Do I need to check for file corruption once scp is done?
scp verifies that it copied all the data sent by the other party. The integrity of the transfer is guaranteed by the cryptographic channel protocol. So you don't need to verify the integrity after the ...
32
votes
How to copy all files from a directory to a remote directory using scp?
Appending /. to your source directory will transfer its contents instead of the directory itself. In contrast to the wildcard solution, this will include any hidden files too.
$ scp -r ~/local_dir/. ...
32
votes
Accepted
Why did 'scp 10.0.0.11:/home/someuser/.*' start copying from /home as well?
It's not the . that goes up a level, but the fact that in the shells' pattern match syntax, * means any number of any characters, so it matches the .. entry that exists in every directory and points ...
29
votes
Accepted
How do I scp via ssh?
To copy from REMOTE to LOCAL:
scp -P 12345 user@server:/path/to/remote/file /path/to/local/file
To copy from LOCAL to REMOTE:
scp -P 12345 /path/to/local/file user@server:/path/to/remote/file
Note:...
28
votes
Accepted
sshpass with SSH works, but sshpass with SCP doesn't
You use an alternative port with ssh -p 2122 but not with scp.
Try
sshpass -p 'myPass' scp -P 2122 ~/myDir/testPB.txt [email protected]:/chroot/tomcat/testPB
Please note upper case P.
As per man ...
26
votes
Transfer files using scp: permission denied
What fixed the "permission denied" for me was, on the remote server, change the folder ownership to root: (This can happen when you are sending a file to a non-root user, and the directory is owned by ...
26
votes
How can I save password,when using SCP (copy)?
You can do:
(if not already done) generate a set of public and private ssh keys on your machine for your user with:
$ ssh-keygen
Answer the questions in order to generate the set of keys.
copy your ...
25
votes
How to copy a file from a remote server to a local machine?
You can use rsync as an alternative. It is mainly for syncing files.. but you can use it for this purpose as well.
rsync -avzh --stats --progress remoteuser@remoteip:/path/ localpath
to add ssh ...
23
votes
how to find out the ip of an ssh HostName
To map from the host argument given on the command line to the ssh_config hostname entry is easy using ssh itself.
You can ask it to evaluate and print out what it would use for the configuration for ...
23
votes
How to copy a file from a remote server to a local machine?
scp ro[email protected]:/root/Jmeter/reports.jtl Downloads/
23
votes
Is scp unsafe? Should it be replaced with sftp?
The way I read it is, "it depends".
According to CVE-2019-6111
However, the scp client only performs cursory validation of the object name returned (only directory traversal attacks are prevented)....
22
votes
Accepted
scp many files without reentering password, all different paths
With OpenSSH you can use its "master mode", whereby you first run an ssh which will establish the connection, authenticate, and then place itself in the background while keeping its ...
21
votes
Accepted
Welcome banner stopping scp
Commands running on top of the ssh transport do not expect large amounts of output before they can start their server. This will affect a number of utilities.
The solution is to have your ...
21
votes
Move (not copy) files from server to a local computer
"Moving" is essentially copying and then deleting the source file.
If you want to "move" a file over the network, you have to do just that.
This is always preferable, since should ...
20
votes
Why is scp so slow and how to make it faster?
It's the negotiation of the transfer that takes time. In general, operations on n files of b bytes each takes much, much longer than a single operation on a single file of n * b bytes. This is also ...
20
votes
scp /path/to/local/file [email protected] creates a new file in local directory?
You need to tell scp you're copying to a remote, using : and (optionally) a path on the target:
scp /path/to/local/file [email protected]:/path/to/remote
If you just specify : it will use ...
20
votes
Accepted
Can I use scp to copy files to the home directory without having to specify it?
Using username@server: as the target should be enough, i.e.
scp somefile username@server:
This would copy the file somefile to the server server and place it in the home directory of the user ...
18
votes
Accepted
Sharing SSH Keys to login?
SSH keys have two parts, the secret/private key (usually in ~/.ssh/id_rsa), and the public key (~/.ssh/id_rsa.pub). The secret key can be used to prove who you are (or at least that you hold that ...
18
votes
Accepted
scp -i my.key "Not a directory" bug - what alternative can I use?
You need to specify the options before the sources and target:
scp -i my.key my.file user@dest:/home/user/
See the synopsis in man scp:
scp [-346ABCpqrTv] [-c cipher] [-F ssh_config] [-i ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scp × 776ssh × 301
linux × 117
rsync × 82
bash × 72
shell-script × 48
sftp × 46
shell × 41
remote × 38
file-transfer × 34
file-copy × 30
ubuntu × 27
networking × 24
files × 21
permissions × 21
scripting × 20
centos × 16
command-line × 16
windows × 16
debian × 12
backup × 12
tar × 12
password × 12
openssh × 12
directory × 11