Site icon Ninotronix

How to Use SCP in Linux: A Step-by-Step Guide with Practical Code Examples for Seamless File Transfer

scp-commands-in-linux

scp-commands-in-linux

scp stands for secure copy, and it is a command-line tool for securely transferring files between local and remote hosts over a network. Here are some practical examples of scp usage:

  1. Copy a file from the local host to a remote host:
scp /path/to/local/file username@remote_host:/path/to/remote/directory
  1. Copy a file from a remote host to the local host:
scp username@remote_host:/path/to/remote/file /path/to/local/directory
  1. Copy a directory recursively from the local host to a remote host:
scp -r /path/to/local/directory username@remote_host:/path/to/remote/directory
  1. Copy a directory recursively from a remote host to the local host:
scp -r username@remote_host:/path/to/remote/directory /path/to/local/directory
  1. Copy multiple files from the local host to a remote host:
scp /path/to/local/file1 /path/to/local/file2 username@remote_host:/path/to/remote/directory
  1. Copy multiple files from a remote host to the local host:
scp username@remote_host:/path/to/remote/file1 username@remote_host:/path/to/remote/file2 /path/to/local/directory
  1. Copy a file using a different port number:
scp -P port_number /path/to/local/file username@remote_host:/path/to/remote/directory

These are just some examples of scp usage. The options and syntax may vary depending on the operating system and version of scp. It’s important to note that scp is a secure way of copying files between hosts, but it is not the most efficient method for transferring large amounts of data.

Exit mobile version