Daten Migration SCP

Data Migration with SCP

Basic Syntax

scp [options] source destination


Examples for Source and Destination

Copy a file from the local machine to a server

scp local_file user@server:/path/to/file

Example:

scp file.txt user@server:/home/user/

This copies file.txt into the user’s home directory on the server.


Copy a file from a server to the local machine

scp user@server:/home/user/file.txt .

The dot (.) means: current directory.


Copy an Entire Directory (Recursive)

From local machine to server

scp -r my_folder user@server:/var/www/


From server to local machine

scp -r user@server:/var/www/my_folder .

Important:
The -r option is mandatory when copying directories.


Using a Different SSH Port

If the server does not use port 22:

scp -P 2222 file.txt user@server:/destination/

Note: Use an uppercase -P.


Using a Specific SSH Key

scp -i ~/.ssh/my_key file.txt user@server:/destination/


Progress Output and Compression

Verbose output (detailed progress)

scp -v file.txt user@server:/destination/

Enable compression (useful for text files)

scp -r -C my_folder user@server:/destination/


Common Practical Examples

Copy multiple files at once

scp file1.txt file2.txt user@server:/destination/


Copy only the contents of a directory

scp -r my_folder/* user@server:/destination/


Save a file under a different name

scp file.txt user@server:/destination/new_name.txt


Common Errors

Permission denied

Possible causes:

  • The user does not have write permissions
  • Wrong user account
  • Missing or incorrect SSH key

Tip:
Test login first:

ssh user@server


No such file or directory

Possible causes:

  • Destination path does not exist
  • Typo in the path

Create the destination directory:

ssh user@server "mkdir -p /destination/"

Kommentieren nicht möglich

Bewertung der FAQ

0 (0 Abstimmungen)