SCP Basics: Difference between revisions

From CompleteNoobs
Jump to navigation Jump to search
AwesomO (talk | contribs)
Created page with "==Transferring files with SCP== The Secure Copy Protocol (SCP) is a useful tool for transferring files between your local machine and a remote server using SSH. SCP ensures that the data is encrypted during transit, providing a secure and efficient way to transfer files. ===Install an SCP client=== Most Unix-based systems, including Linux and macOS, have an SCP client pre-installed. For Windows, you can use the built-in SCP client included with the OpenSSH package (a..."
 
(No difference)

Latest revision as of 22:11, 3 June 2025

Transferring files with SCP

The Secure Copy Protocol (SCP) is a useful tool for transferring files between your local machine and a remote server using SSH. SCP ensures that the data is encrypted during transit, providing a secure and efficient way to transfer files.

Install an SCP client

Most Unix-based systems, including Linux and macOS, have an SCP client pre-installed. For Windows, you can use the built-in SCP client included with the OpenSSH package (available in Windows 10 and later) or a third-party client like WinSCP.

Transfer a file from your local machine to a remote server

To copy a file from your local machine to a remote server, use the following command:

  • Note the use of the upper case -P for ports with scp

scp -P port local_file_path username@hostname_or_IP:remote_file_path

Replace port with the SSH port number (if different from the default 22), local_file_path with the path to the file on your local machine, username with your username on the remote server, hostname_or_IP with the server's hostname or IP address, and remote_file_path with the desired location on the remote server.

For example:

scp -P 22 /home/john/documents/report.pdf john@example.com:/home/john/reports/

This command will copy the "report.pdf" file from the local machine to the "reports" directory on the remote server.

Transfer a file from a remote server to your local machine

To copy a file from a remote server to your local machine, use the following command:

scp -P port username@hostname_or_IP:remote_file_path local_file_path

Replace port with the SSH port number (if different from the default 22), username with your username on the remote server, hostname_or_IP with the server's hostname or IP address, remote_file_path with the path to the file on the remote server, and local_file_path with the desired location on your local machine.

For example:

scp -P 2222 john@example.com:/home/john/reports/report.pdf /home/john/documents/

Or

scp john@example.com:/home/john/reports/report.pdf /home/john/documents/-

This command will copy the "report.pdf" file from the remote server's "reports" directory to the "documents" directory on your local machine.

Transferring directories

To transfer an entire directory, use the -r flag:

scp -r -P port local_directory_path username@hostname_or_IP:remote_directory_path

Or, to copy a directory from the remote server to your local machine:

scp -r -P port username@hostname_or_IP:remote_directory_path local_directory_path

Using SCP is a convenient and secure way to transfer files between your local machine and a remote server. It leverages the security of the SSH protocol to ensure that your data remains encrypted during transit.

Transferring from Remote Computer to Remote Computer

Copy the file stuff.txt from remote host 12.34.56.67 to host 11.22.33.44


scp name@12.34.56.67:/home/user/Documents/stuff.txt name@11.22.33.44:/home/user/Documents/

With the -3 flag copies between two remote hosts "12.34.56.67" and "11.22.33.44" are transferred through the local host running the command.

scp -3 name@12.34.56.67:/home/user/Documents/stuff.txt \ name@11.22.33.44:/home/user/Documents/

Transferring multiple files

Send files foo.txt and bar.txt to remote.

scp foo.txt bar.txt user@12.34.56.78:~/Documents/


Copy multiple files from remote "Documents" directory to local "Documents" directory.

scp user@11.22.33.44:/home/user/Documents/\{todo_list.txt,links.txt,stuff.txt\} /home/$USER/Documents/


Copy multiple files from the remote to local current directory.

scp name@12.34.56.78:~/\{README.md,.bashrc\} .