Last modified: May 31, 2006 by Kachelhoffer
SSH: to copy a file with the scp command
1. Definition
The
scp command allows you to copy a file or a directory (-r) from the client to a server or from a server to the client. The path of the server could be given in absolute (
/home/dupont/Directory for example) or relatively from the base directory
Directory. To use
scp, you should know the correct paths of the directories on the remote server. Also,
SSH should be installed on the two servers which should communicate to make your transfert.
BE CAREFULL: at Computing Center, you should give your password. It is not possible to make an authentification using SSH keys exchange (see
To connect at Computing Center using SSH).
2. Usage
scp [-pqrvBC1246] [-F ssh_config] [-S program] [-P port] [-c cipher]
[-i identity_file] [-l limit] [-o ssh_option] [[user@]host1:]file1
[...] [[user@]host2:]file2
3. Syntaxe
- To copy a file from a server called server1 to an other one called server2:
> scp Login1@Server1:Path1/File1 Login2@Server2:Path2/File2
- To copy a local file from the current directory to a directory on the remote server:
> scp File Login@Server:Path/
- To copy a local directory, with sub-directories if any, to a directory on the remote server:
> scp -r Directory Login@Server:Path/
- To copy a file from the remote server to the current local directory:
> scp Login@Server:Path/File .
- To copy a directory from the remote serveur to the current local directory:
> scp -r Login@Server:Path/Directory .
4. Examples
> scp calvat@ccali.in2p3.fr:/afs/in2p3.fr/home/c/calvat/Readme.txt .
copy the file
Readme.txt from
/afs/in2p3.fr/home/c/calvat on ccali.in2p3.fr to the current local directory.
> scp -r calvat@ccali.in2p3.fr:/afs/in2p3.fr/home/c/calvat/toto .
copy the directory
toto and the attached sub-directories from
/afs/in2p3.fr/home/c/calvat on ccali.in2p3.fr to the current local directory.