Hot answers tagged

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 ...
parazyd's user avatar
  • 2,499
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 ...
Chris Davies's user avatar
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 ...
tachomi's user avatar
  • 7,512
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: ...
A.B's user avatar
  • 33.4k
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 ...
JoL's user avatar
  • 4,590
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 ...
maizer's user avatar
  • 531
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, ...
Martin Prikryl's user avatar
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.
blaimi's user avatar
  • 1,120
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 ...
Ángel's user avatar
  • 3,539
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 ...
eadmaster's user avatar
  • 1,613
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 ...
Gilles 'SO- stop being evil''s user avatar
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/. ...
raphinesse's user avatar
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 ...
ilkkachu's user avatar
  • 135k
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:...
jesse_b's user avatar
  • 36.4k
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 ...
Archemar's user avatar
  • 31.4k
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 ...
Stan Tatarnykov's user avatar
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 ...
fduff's user avatar
  • 4,985
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 ...
fugitive's user avatar
  • 1,543
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 ...
Lloyd Pique's user avatar
23 votes

How to copy a file from a remote server to a local machine?

scp ro[email protected]:/root/Jmeter/reports.jtl Downloads/
user135545's user avatar
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)....
Archemar's user avatar
  • 31.4k
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 ...
LL3's user avatar
  • 5,338
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 ...
Chris Davies's user avatar
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 ...
polemon's user avatar
  • 11.2k
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 ...
dr_'s user avatar
  • 29.2k
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 ...
Stephen Kitt's user avatar
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 ...
Kusalananda's user avatar
  • 327k
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 ...
ilkkachu's user avatar
  • 135k
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 ...
Stephen Kitt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible