Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

SCP

News SSH Recommended Links bash Tips and Tricks Private and Public key management Reference WinSCP
ssh-keygen man page SSH Usage in Pipes sftp ssh_tips SCP Tips Humor Etc

Introduction

Utility scp is a part of SSH suit allows files to be copied between machines. It is an updated version of an older utility named rcp, which is a part of rsh package initially developed by Sun, which in turn was  based on BSD source code from the Regents of the University of California.

It works the same, except that information it transfers (including the password used to log in) is encrypted. Also, if you have set up passwordless certificate. Like in rcp you also can use older method based on .shosts file to allow you to SSH between machines without using a password. There is a wrapper for scp which allows passwords via Expect ( NetSCPExpect - search.cpan.org )

This is a command line utility. GUI SCP clients are rare, as implementing it requires additional functionality (directory listing of the remote host at least). The most popular is WinSCP which actually defaults to the SFTP protocol. Even when operating in SCP mode, clients like WinSCP are typically not pure SCP clients, as they must use other means to implement the additional functionality (like the ls command).

The general form of the command is similar to cp command:

	 scp source-specification destination-specification

where source-specification indicates which file or directory is to be copied, and destination-specification indicates where the copied material is to be placed. Like in cp option -p Preserves modification times, access times, and modes from the original file.

Either the source or the destination may be on the remote machine; i.e., you may copy files or directories into any account on the remote system OR copy them from the account on the remote system into the account you are logged into.

Example:

	 scp myfile user@server:myfile	
To copy a directory, use the -r (recursive) option. Example:
	 scp -r mydir user@server:/mydir	

The format for the remote specification (source or destination) is:

	user@machine :filename	

where filename is the name (path) of the file or directory relative to the home directory of particular user on the remote system. For local file in the current directory you can use just filename.

Just like the cp command, scp will overwrite an existing destination file. In addition, if the destination is an existing directory, the copied material will be placed into this directory.

Does scp create the target folder if it does not exist

The short answer is no. But scp is part of ssh you can combine it with ssh command to solve the problem. There are several ways to sove this problem

  1. You can achieve the goal using ssh + scp (instead of rsync):

    You can do the same from the other end:

    target="[email protected]"
    source='[email protected]"
    dest="/home/joeuser/somefolder"
    src=$dest
    ssh $target "[ -d $dest ] && mkdir -p $des";  scp -r $dest $source:$dest"
  2. You can use tar with ssh instead of scp.  See SSH Usage in Pipes
     
  3. If you need to copy a subtree you can use -r switch.
     
  4. If rsync is installed on the server you can use it qith the folloqwing options  rsync -Pravdtze ssh.  Which in combination produces my preferred rsync behavior.

  5. You can also use rdist

See also Does scp create the target folder if it does not exist

Examples

  1. While logged into user on server, copy file "letter" into file "application" in remote account abc on sdcc3:
    	scp letter abc@sdcc3:application	
  2. While logged into abc on sdcc3, copy file "foo" from remote account user on server into filename "bar" in abc:
    	 scp user@server:foo bar	
  3. While logged into account user on server, copy file "garfield" from subdirectory "comix" into filename "fatcat" in subdirectory "stuff" in remote account abc on sdcc3:
    	 scp comix/garfield abc@sdcc3:stuff/fatcat
  4. While logged into account abc on sdcc3, copy file "garfield" from subdirectory "comix" of account user on server into subdirectory "stuff" with the same name "garfield":
    	 scp user@server:comix/garfield stuff
    	
  5. While logged into account abc on sdcc3 , copy subdirectory "Section" into a new subdirectory called "Section" in existing subdirectory "Chapter" in account user on server:
    	 scp -r Section user@server:Chapter	
  6. From account abc on sdcc3, copy entire account to ir123 on iacs5. This needs to be done from the parent directory of the account to be moved.
    	 cd
    	 cd ..
    	 scp -r abc ir123@iacs5:abc
Edit a file on a remote host using vim
vim scp://username@host//path/to/somefile
Colored diff ( via vim ) on 2 remotes files on your local computer.
vimdiff scp://[email protected]//etc/snmp/snmpd.conf scp://[email protected]//etc/snmp/snmpd.conf
Restrict the bandwidth for the SCP command
scp -l10 [email protected]:/home/urfix/* .

Maybe not everyone knows that using the parameter “-l” you can limit the use of bandwidth command scp.
In this example fetch all files from the directory zutaniddu and I copy them locally using only 10 Kbs

Compare a remote file with a local file
vimdiff  scp://[@]/
Easily scp a file back to the host you’re connecting from
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }

Place in .bashrc and invoke like this: “mecp /path/to/file”, and it will copy the specified file(s) back to the desktop of the host you’re ssh’ing in from. To easily upload a file from the host you’re ssh’ing in from use this:

ucp (){ scp ${SSH_CLIENT%% *}:Desktop/upload/* .; }
scp file from hostb to hostc while logged into hosta
scp user@hostb:file user@hostc:

While at the command line of of hosta, scp a file from remote hostb to remote hostc. This saves the step of logging into hostb and then issuing the scp command to hostc.

Copy something to multiple SSH hosts with a Bash loop
for h in host1 host2 host3 host4 ; do
   scp file user@$h:/destination_path/ ; 
done

Just a quick and simple one to demonstrate Bash For loop. Copies ‘file’ to multiple ssh hosts.

scp with compression.
scp -C 10.0.0.4:/tmp/backup.sql /path/to/backup.sql

 For more information about the scp (secure copy) command, check the on-line manual page for scp:

	 man scp

SCP (Secure CoPy) and SSH in general can be used in batch mode without asking for passwords. That is very convenient for scripts.

Procedure for creating private/public key pair

1. In this instructions, the user name is the same in both machines. Instructions for different user names could differ from these (but see note below!)

2. The user keys will be stored in ~/.ssh in both machines.

3. At the client, run 'ssh-keygen -t dsa' to generate a key pair. Accept default options by pressing return. Specially, do not enter any passphrase. (Option -d seems to be an alias of -t dsa in some platforms).

4. Change the permissions of the generated .pub file to 600 by commanding chmod 600 id_dsa.pub

5. Copy the public key to the server with scp id_dsa.pub 'user@server:~/.ssh/authorized_keys'. (Caution: if that destination file already exists on the server, copy first to a different file foo and then append the contents with cat foo >> authorized_keys executed on the server).

6. Done! Verify that now you can connect directly from the client with ssh user@server without being prompted for a password.

7. If it doesn't work, verify that in the server your home directory, the .ssh subdirectory, and the authorized_keys file do not have writing permissions to others. If they do, they won't be considered to grant access. You can correct this with something like:

 chmod 755 ~
 chmod 700 ~/.ssh
 chmod 600 ~/.ssh/authorized_keys

8. If it still doesn't work, try changing the authorized_keys file name to authorized_keys2, or ask your system administrator what file name is ssh actually using.

9. If it worked, you can now run SCP in batch mode with the -B option, as in scp -B foofile 'user@server:~/foodir/'.

Notes

The name of the server must have been registered in the known_hosts. This can be done with a regular (with password) ssh connection, and accepting the host as known. Then, the host name should be the same as the one accepted! If you used user@server first, do not use [email protected] later on!

SSH protocol 2 is assumed in this procedure (it uses dsa keys). If your ssh configuration files (at /etc/ssh/) do not establish this as a default, you may have to force it with the -2 option of the ssh and scp. Moreover, if the default public key is not configured to be "id_dsa.pub" you can specify what key to use for identification with the -i option.

The same procedure worked fine when the username was different in both machines. I simply copied userA's public key at the end of userB's authorized_keys file, then I could login from my client as userA with ssh userB@server.


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[Aug 20, 2019] How to exclude file when using scp command recursively

Aug 12, 2019 | www.cyberciti.biz

I need to copy all the *.c files from local laptop named hostA to hostB including all directories. I am using the following scp command but do not know how to exclude specific files (such as *.out): $ scp -r ~/projects/ user@hostB:/home/delta/projects/ How do I tell scp command to exclude particular file or directory at the Linux/Unix command line? One can use scp command to securely copy files between hosts on a network. It uses ssh for data transfer and authentication purpose. Typical scp command syntax is as follows: scp file1 user@host:/path/to/dest/ scp -r /path/to/source/ user@host:/path/to/dest/ scp [options] /dir/to/source/ user@host:/dir/to/dest/

Scp exclude files

I don't think so you can filter or exclude files when using scp command. However, there is a great workaround to exclude files and copy it securely using ssh. This page explains how to filter or excludes files when using scp to copy a directory recursively.

How to use rsync command to exclude files

The syntax is:

rsync -av -e ssh --exclude='*.out' /path/to/source/ user@hostB:/path/to/dest/

Where,

  1. -a : Recurse into directories i.e. copy all files and subdirectories. Also, turn on archive mode and all other options (-rlptgoD)
  2. -v : Verbose output
  3. -e ssh : Use ssh for remote shell so everything gets encrypted
  4. --exclude='*.out' : exclude files matching PATTERN e.g. *.out or *.c and so on.
Example of rsync command

In this example copy all file recursively from ~/virt/ directory but exclude all *.new files:
$ rsync -av -e ssh --exclude='*.new' ~/virt/ root@centos7:/tmp

[Mar 04, 2017] shell - How to scp a folder from remote to local - Stack Overflow

Notable quotes:
"... Did not know about the config file, this is awesome! ..."
Feb 18, 2017 | stackoverflow.com
How to scp a folder from remote to local? [closed]
Ask Question up vote 1197 down vote favorite 340

I am not sure whether it is possible to scp a folder from remote to local, but still I am left with no other options. I use ssh to log into my server and from there I would like to copy the folder foo to home/user/Desktop (my local). Is there any command so that I can do this?

To use full power of scp you need to go through next steps:

  1. Public key authorisation
  2. Create ssh aliases

Then, for example if you'll have this ~/.ssh/config :


Host
 test
    
User
 testuser
    
HostName
 test
-
site
.
com
    
Port
22022
Host
 prod
    
User
 produser
    
HostName
 production
-
site
.
com
    
Port
22022

you'll save yourself from password entry and simplify scp syntax like this:


scp 
-
r prod
:/
path
/
foo 
/
home
/
user
/
Desktop
# copy to local

scp 
-
r prod
:/
path
/
foo test
:/
tmp            
# copy from remote prod to remote test

More over, you will be able to use remote path-completion:


scp test
:/
var
/
log
/
# press tab twice
Display
 all 
151
 possibilities
?
(
y or n
)

Update:

For enabling remote bash-completion you need to have bash-shell on both <source> and <target> hosts, and properly working bash-completion. For more information see related questions:

How to enable autocompletion for remote paths when using scp?
SCP filename tab completion

6
Did not know about the config file, this is awesome! dmastylo Mar 1 '14 at 20:27

What I always use is:


scp 
-
r username@IP
:/
path
/
to
/
server
/
source
/
folder
/
.

. (dot) : it means current folder . so copy from server and paste here only.

IP : can be an IP address like 125.55.41.311 or it can be host like ns1.mysite.com .

[Feb 18, 2017] ssh - scp without replacing existing files in the destination - Unix Linux Stack Exchange

Notable quotes:
"... scp will overwrite the files only if you have write permissions to them. In other words: You can make scp effectively skip said files by temporarily removing the write permissions on them (if you are the files' owner, that is). ..."
"... before running scp (it will complain and skip the existing files). And change them back afterward ( chmod +w to get umask based value). If the files do not all have write permission according to your umask, you would somehow have to store the permissions so that you can restore them. (Gilles' answer overwrites existing files if locally they are newer, I lost valuable data that way. Do not understand why that wrong and harmful answer has so many up votes). I don't get it: how did rsync --ignore-existing cause you to lose data? – ..."
"... Unable to create temporary file Clock skew detected ..."
"... In my case - I could not do this and the solution was: lftp . lftp 's usage for syncronization is below: ..."
"... To copy a whole bunch of files, it's faster to tar them. By using -k you also prevent tar from overwriting files when unpacking it on the target system. ..."
Feb 18, 2017 | unix.stackexchange.com

scp without replacing existing files in the destination

How do I copy an entire directory into a directory of the same name without replacing the content in the destination directory? (instead, I would like to add to the contents of the destination folder) ssh rsync scp synchronization

Use rsync , and pass -u if you want to only update files that are newer in the original directory, or --ignore-existing to skip all files that already exist in the destination.
rsync -au /local/directory/ host:/remote/directory/
rsync -a --ignore-existing /local/directory/ host:/remote/directory/

(Note the / on the source side: without it rsync would create /remote/directory/directory .)

@Anthon I don't understand your comment and I don't see an answer or comment by chandra. --ignore-existing does add without replacing, what data loss do you see? – Gilles Nov 27 '13 at 9:59

Sorry, I only looked at your first example that is where you can have data loss (and is IMHO not what the OP asked for), if you include --ignore-existing data-loss should not happen. – Anthon Nov 27 '13 at 10:08

This does not help if the remote system does not have rsync easily available.... (Like Win32-OpenSSH) – Gert van den Berg Oct 25 '16 at 8:00

@GertvandenBerg rsync is pretty easy to install on Windows, no harder than SSH. – Gilles Oct 25 '16 at 11:51

@Gilles: True, but all of the options seems to involve Cygwin DLLs... (The current state of the MS port of OpenSSH is such that enabling compression on scp is enough to break SCP...) (Getting rsync functional over Win32-OpenSSH also seems non-trivial - hopefully that improves over time) (Solaris 10 is the other example, where a third party package and --rsync-path is needed) – Gert van den Berg Oct 25 '16 at 13:01

scp will overwrite the files only if you have write permissions to them. In other words: You can make scp effectively skip said files by temporarily removing the write permissions on them (if you are the files' owner, that is).

Anthon 49.6k 14 68 132 answered Oct 15 '12 at 21:10 Reimund 491 4 2

Thanks for this. Was exactly the trick I was looking for. – saccharine Jul 16 '13 at 21:02

make sure you copy the files back you add a * to do so. Example scp -r [email protected]:/location/of/files/* /local/location/ Rick May 27 '15 at 19:16

find . -type f -exec chown root:root {} \; – ling Aug 21 '16 at 19:58

You can copy only new files by date. Use find

scp  `find /data/*.gz -type f -mtime +7` USER@SERVER:/backup/

Naks

If you can make the destination file contents read-only:

find . -type f -exec chmod a-w

before running scp (it will complain and skip the existing files). And change 
      them back afterward ( chmod +w to get umask based value). If the files do not all 
      have write permission according to your umask, you would somehow have to store the permissions 
      so that you can restore them. 

(Gilles' answer overwrites existing files if locally they are newer, I lost valuable data that way. Do not understand why that wrong and harmful answer has so many up votes).

I don't get it: how did rsync --ignore-existing cause you to lose data? – Gilles Nov 27 '13 at 10:01 add a comment |

I had a similar task, in my case I could not use rsync , csync , or FUSE because my storage has only SFTP. rsync could not change the date and time for the file, some other utilities (like csync ) showed me other errors: " Unable to create temporary file Clock skew detected ".

If you have access to the storage-server - just install openssh-server or launch rsync as a daemon here.

In my case - I could not do this and the solution was: lftp . lftp 's usage for syncronization is below:

lftp -c "open -u login,password sftp://sft.domain.tld/; \
    mirror -c --verbose=9 -e -R -L /srs/folder /rem/folder"

/src/folder - is the folder on my PC, /rem/folder - is sftp://sft.domain.tld/rem/folder .

You may find man pages by the link: http://lftp.yar.ru/lftp-man.html

scp does overwrite files and there's no switch to stop it doing that, but you can copy things out the way, do the scp and then copy the existing files back. Examples:

  1. Copy all existing files out the way
    mkdir original_files ; cp -r * original_files/
    
    
  2. Copy everything using scp
    scp -r user@server:dir/* ./
    
    
  3. Copy the original files over anything scp has written over:
    cp -r original_files/* ./
    
    

This method doesn't help when you're trying to pull files over from a remote and pick up where you left off. I.e. if the whole purpose is to save time. – Oliver Williams Dec 1 '16 at 17:58

>To copy a whole bunch of files, it's faster to tar them. By using -k you also prevent tar from overwriting files when unpacking it on the target system.

tar -c <source-dir> | ssh <name>@<host> 'tar -kxzf - -C <target-dir>' 

It does make a remote connection. First it tar's the source, pipes it into the ssh connection and unpacks it on the remote system. – huembi Aug 22 '16 at 21:17

[Dec 07, 2015] How to resume a large SCP file transfer on Linux

Ask Xmodulo

Originally based on BSD RCP protocol, SCP (Secure copy) is a mechanism that allows you to transfer a file between two end points over a secure SSH connection. However, as a simple secure copy protocol, SCP does not understand range-request or partial transfer like HTTP does. As such, popular SCP implementations like the scp command line tool cannot resume aborted downloads from lost network connections.

If you want to resume an interrupted SCP transfer, you need to rely on other programs which support range requests. One popular such program is rsync. Similar to scp, rsync can also transfer files over SSH.

Suppose you were trying to download a file (bigdata.tgz) from a remote host remotehost.com using scp, but the SCP transfer was stopped in the middle due to a stalled SSH connection. You can use the following rsync command to easily resume the stopped transfer. Note that the remote server must have rsync installed as well.

$ cd /path/to/directory/of/partially_downloaded_file
$ rsync -P -rsh=ssh [email protected]:bigdata.tgz ./bigdata.tgz

The "-P" option is the same as "--partial --progress", allowing rsync to work with partially downloaded files. The "-rsh=ssh" option tells rsync to use ssh as a remote shell.

[Dec 20, 2014] linux - Does scp create the target folder if it does not exist

Stack Overflow

Does scp create the target folder if it does not exist

I am wondering if scp will create the target folder if it does not exist on the remote server. For example, would this work?

scp -r /home/joeuser/somefolder [email protected]:/home/joeuser/somefolder

Here the folder /home/joeuser/somefolder doesn't exist on ftp server, so would this command create it?

N.B. I have read about rsync but am not really sure how it works or how to use it yet.

linux bash scp

What does the ssh/scp manual or documentation say? – Jens Oct 17 '12 at 8:51

Short answer: no.

...but rsync does, which is why i have aliased scp to rsync -Pravdtze ssh on my box. Yes, that's a lot of switches, which in combination produces my preferred rsync behavior. As rsync does provide a very extensive set of switches and options, i suggest you do some research on it to see what fits your needs best. Manpage is a good place to start, but there are a lot of info easily available. Here's a decent list of examples.

Edit: Actually, in that particular case you posted, the folder will be created, as that's the folder you're copying. However, if you're trying to copy it to user@remotehost:somenonexistentfolder/somefolder, then it will fail.


To achieve the task with ssh and scp (instead of rsync):

Solution

Lets break into 2 steps :

1. Create directory if missing:

ssh [email protected] 'mkdir -p /home/joeuser/somefolder'

2. Copy to it:

scp -r /home/joeuser/somefolder [email protected]:/home/joeuser/somefolder

Put them together

server="[email protected]"
destiny="/home/joeuser/somefolder"
src="/home/joeuser/somefolder"
ssh "$server" "mkdir -p $destiny" && scp -r "$src" "$server:$destiny"

[May 08, 2014] 8 Cool Ways To Use SCP

October 14, 2011 | blog.urfix.com
Edit a file on a remote host using vim
vim scp://username@host//path/to/somefile
Colored diff ( via vim ) on 2 remotes files on your local computer.
vimdiff scp://[email protected]//etc/snmp/snmpd.conf scp://[email protected]//etc/snmp/snmpd.conf
Restrict the bandwidth for the SCP command
scp -l10 [email protected]:/home/urfix/* .

the command is obvious, I know, but maybe not everyone knows that using the parameter "-l" you can limit the use of bandwidth command scp.
In this example fetch all files from the directory zutaniddu and I copy them locally using only 10 Kbs

Compare a remote file with a local file
vimdiff  scp://[@]/
Easily scp a file back to the host you're connecting from
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }

Place in .bashrc and invoke like this: "mecp /path/to/file", and it will copy the specified file(s) back to the desktop of the host you're ssh'ing in from. To easily upload a file from the host you're ssh'ing in from use this:

ucp (){ scp ${SSH_CLIENT%% *}:Desktop/upload/* .; }
scp file from hostb to hostc while logged into hosta
scp user@hostb:file user@hostc:

While at the command line of of hosta, scp a file from remote hostb to remote hostc. This saves the step of logging into hostb and then issuing the scp command to hostc.

Copy something to multiple SSH hosts with a Bash loop
for h in host1 host2 host3 host4 ; { scp file user@$h:/destination_path/ ; }

Just a quick and simple one to demonstrate Bash For loop. Copies 'file' to multiple ssh hosts.

scp with compression.
scp -C 10.0.0.4:/tmp/backup.sql /path/to/backup.sql

[Aug 27, 2010] How To Execute SSH and SCP in Batch Mode (Only when Passwordless login is enabled) by Ramesh Natarajan

October 28, 2009

2. scp -B option Usage Example

If you use scp -B option, it will execute scp only if the passwordless login is enabled, else it will exit immediately without waiting for password.

$ scp -B file root@IP:PATH

SCP in Batch mode - Successful Case

local-host# scp -B /etc/yp.conf ramesh@remote-host:/tmp
yp.conf            100   84     0.1KB/s   00:00

SCP in Batch mode - Failure Case

In this example, if scp is possible without authentication, the command will execute else it will exit as shown below.

local-host# scp -B /etc/yp.conf ramesh@remote-host:/tmp
Permission denied (publickey,password).
lost connection

Scp -- Secure File Transfer between UNIX machines

Scp is an updated version of an older utility named Rcp. It works the same, except that information (including the password used to log in) is encrypted.

Just like the cp command, scp will overwrite an existing destination file. In addition, if the destination is an existing directory, the copied material will be placed beneath the directory.

Also, if you have set up your .shosts file to allow you to ssh between machines without using a password as described in help on setting up your .shosts file, you will be able to scp files between machines without entering your password.

The general form of the command is:

	 scp source-specification destination-specification	

where source-specification indicates which file or directory is to be copied, and destination-specification indicates where the copied material is to be placed.

Either the source or the destination may be on the remote machine; i.e., you may copy files or directories into the account on the remote system OR copy them from the account on the remote system into the account you are logged into.

Example:

	 scp myfile user@server:myfile
	
To copy a directory, use the -r (recursive) option. Example:
	 scp -r mydir user@server:mydir
	

The format for the remote specification (source or destination) is:

	user@machine:filename
	

where filename is the name (path) of the file or directory relative to the home (login) directory on the remote system.

The format for file specification on the local system is just:

	filename
	

where fname is the name (path) relative to the current working directory on that system.

Examples of remote file copies

  1. While logged into user on server, copy file "letter" into file "application" in remote account abc on sdcc3:
    	 scp letter abc@sdcc3:application
    	
  2. While logged into abc on sdcc3, copy file "foo" from remote account user on server into filename "bar" in abc:
    	 scp user@server:foo bar
    
    	
  3. While logged into account user on server, copy file "garfield" from subdirectory "comix" into filename "fatcat" in subdirectory "stuff" in remote account abc on sdcc3:
    	 scp comix/garfield abc@sdcc3:stuff/fatcat
    	
  4. While logged into account abc on sdcc3, copy file "garfield" from subdirectory "comix" of account user on server into subdirectory "stuff" with the same name "garfield":
    	 scp user@server:comix/garfield stuff	
  5. While logged into account abc on sdcc3 , copy subdirectory "Section" into a new subdirectory called "Section" in existing subdirectory "Chapter" in account user on server:
    	 scp -r Section user@server:Chapter
    	
  6. From account abc on sdcc3, copy entire account to ir123 on iacs5. This needs to be done from the parent directory of the account to be moved.
    	 cd
    	 cd ..
    	 scp -r abc ir123@iacs5:abc
    	

For more information about the scp (secure copy) command, check the on-line manual page for scp:

	 man scp

Copying Files with scp

To copy files between two machines, say 192.168.1.101 and 192.168.1.100, sit at 192.168.1.101 and use the following command:

scp * 192.168.1.100:

Simple as that! Assuming you are the same user id on both machines, this will copy all files in the current directory to your home directory on the destination machine, 192.168.1.100. The first thing the command will do, though, is ask you for your password on the remote system - once you supply that, then you'll see the files copied, with progress bars.

Now, if you want to copy only some files, e.g. all txt files, use a standard wildcard, like this:

scp *.txt 192.168.1.100:

Suppose you want to copy them to a destination directory other than your home directory, use:

scp *.txt 192.168.1.100:/home/username/directory

Of course, you have to have write permission on the target directory.

Suppose you want to copy files from the other machine back to the one you're on - then use this syntax:

scp 192.168.1.100:*.txt .

If you have a DNS or hosts file set up, then you can (and should) use hostnames in the command, like this:

scp mail/* mailsrvr:/home/joe/mail

This will copy the contents of the mail subdirectory (of the current directory) on this machine, to the directory /home/joe/mail on the machine mailsrvr.

Recommended Links

Google matched content

Softpanorama Recommended

Top articles

Sites

Reference

Section: SSH (1)
Updated: November 8, 1995

scp - secure copy (remote file copy program)

scp [ -aAqQprvBCL1 ][ -S path-to-ssh][ -o ssh-options][ -P port][ -c cipher][ -i identity]
[[ user@ ] host1: ] filename1 ...[[ user@ ] host2: ] filename2

Scp copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides thesame security as ssh. Unlike rcp , scp will ask for passwords or passphrases if they are needed forauthentication.

Any file name may contain a host and user specification to indicatethat the file is to be copied to/from that host. Copies between tworemote hosts are permitted.

Options

-a
Turn on statistics display for each file.
-A
Turn off statistics display for each file.
-c cipher
Selects the cipher to use for encrypting the data transfer. Thisoption is directly passed to ssh.
-i identity_file
Selects the file from which the identity (private key) for RSA authentication is read. This option is directly passed to ssh.
-L
Use non privileged port. With this you cannot user hosts or rsa rhosts authentications, but it can be used to bypass some firewalls that dont allow privileged source ports to pass. Same as saying "-o UsePriviledgePort=no"or -P to ssh; -L is used due to exhaustion of suitable letters.
-1
Force scp to use command "scp1" on the remote side instead of "scp".This may be necessary in some situations, if the remote system has"scp2" symlinked to "scp".
-o ssh-options
Ssh options passed to ssh.
-p
Preserves modification times, access times, and modes from the original file.
-q
Turn off statistics display.
-Q
Turn on statistics display.
-r
Recursively copy entire directories.
-v
Verbose mode. Causes scp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.
-B
Selects batch mode (prevents asking for passwords or pass phrases).
-C
Compression enable. Passes the -C flag to ssh to enable compression.
-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.
-S path-to-ssh
Specifies the path to ssh program.

ENVIRONMENT VARIABLES

You can turn scp statistics on or off by setting SSH_SCP_STATS or SSH_NO_SCP_STATS environment variables. To turn on or off scp statistics for each file,use SSH_ALL_SCP_STATS or SSH_NO_ALL_SCP_STATS environment variables. The default value of the statistics can be setwhen the ssh is configured. Next the scp checks those environmentvariables and after that command line options.

SCP(1) OpenBSD Reference Manual SCP(1)

NAME
scp - secure copy (remote file copy program)

SYNOPSIS
scp [ -1246BCpqrv ] [ -c cipher] [ -F ssh_config] [ -i identity_file]
[ -l limit] [ -o ssh_option] [ -P port] [ -S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2

DESCRIPTION
scp copies files between hosts on a network. It uses ssh(1) for data
transfer, and uses the same authentication and provides the same security
as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if
they are needed for authentication.

Any file name may contain a host and user specification to indicate that
the file is to be copied to/from that host. Copies between two remote
hosts are permitted.

The options are as follows:

-1 Forces scp to use protocol 1.

-2 Forces scp to use protocol 2.

-4 Forces scp to use IPv4 addresses only.

-6 Forces scp to use IPv6 addresses only.

-B Selects batch mode (prevents asking for passwords or passphras-
es).

-C Compression enable. Passes the -C flag to ssh(1) to enable com-
pression.

-c cipher
Selects the cipher to use for encrypting the data transfer. This
option is directly passed to ssh(1).

-F ssh_config
Specifies an alternative per-user configuration file for ssh .
This option is directly passed to ssh(1).

-i identity_file
Selects the file from which the identity (private key) for RSA
authentication is read. This option is directly passed to
ssh(1).

-l limit
Limits the used bandwidth, specified in Kbit/s.

-o ssh_option
Can be used to pass options to ssh in the format used in
ssh_config(5). This is useful for specifying options for which
there is no separate scp command-line flag. For full details of
the options listed below, and their possible values, see
ssh_config(5).

AddressFamily
BatchMode
BindAddress
ChallengeResponseAuthentication
CheckHostIP
Cipher
Ciphers
Compression
CompressionLevel
ConnectionAttempts
ConnectionTimeout
GlobalKnownHostsFile
GSSAPIAuthentication
GSSAPIDelegateCredentials
Host
HostbasedAuthentication
HostKeyAlgorithms
HostKeyAlias
HostName
IdentityFile
IdentitiesOnly
LogLevel
MACs
NoHostAuthenticationForLocalhost
NumberOfPasswordPrompts
PasswordAuthentication
Port
PreferredAuthentications
Protocol
ProxyCommand
PubkeyAuthentication
RhostsRSAAuthentication
RSAAuthentication
ServerAliveInterval
ServerAliveCountMax
SmartcardDevice
StrictHostKeyChecking
TCPKeepAlive
UsePrivilegedPort
User
UserKnownHostsFile
VerifyHostKeyDNS

-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(1).

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

-q Disables the progress meter.

-r Recursively copy entire directories.

-S program
Name of program to use for the encrypted connection. The program
must understand ssh(1) options.

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

DIAGNOSTICS
scp exits with 0 on success or >0 if an error occurred.

SEE ALSO
rcp(1), sftp(1), ssh(1), ssh-add(1), ssh-agent(1), ssh-keygen(1),
ssh_config(5), sshd(8)

HISTORY
scp is based on the rcp(1) program in BSD source code from the Regents of the University of California.

AUTHORS
Timo Rinne <[email protected]>
Tatu Ylonen <[email protected]>




Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: August, 20, 2019