Blog / How to transfer files between servers using SSH?

How to transfer files between servers using SSH?

by SW Team

File transfer and remote server administration are key tasks for any IT professional or developer.

In this blog, we will explore two essential tools that facilitate these processes: SSH (Secure Shell) and SCP (Secure Copy Protocol).

What is SSH?

SSH (Secure Shell) is a protocol that allows you to access or remotely manage a computer. It is based on the command line and can be used on Windows, Mac and Linux systems. Most servers, especially those running Linux, come with default SSH enabled.

Concepts

Server: a "service" or program that is always running and is waiting to receive connections. When a connection is received, the credentials are validated and, if they are correct, the user acquires access and goes on to manage the equipment as if it was physically connected to it.

Client: a program that uses the SSH protocol so that a user can access another computer

Examples of SSH servers according to operating system:

  • Windows: WinSSH
  • Linux / Mac: openssh-server

Examples of SSH clients according to operating system:

  • Windows: through third-party applications such as PuTTY
  • Linux / Mac: natively included, using console or terminal and lassh la command

Mainly on Linux, but there is also client and server for Windows.

What is SCP?

SCP (Secure Copy Protocol also known as Secure Copy) is a secure copying protocol. The copy uses the SSH protocol to securely transfer files between teams. Allows secure loading and downloading (transfer) of files between local and/or remote equipment.

In SCP there are clients for Windows (WinSCP) and Linux (SCP).

Examples of SCP clients according to operating system:

  • Windows: through third-party applications such as WinSCP
  • Linux / Mac: natively included, using console or terminal and lascp la command

Advantages of using SCP

  • Secure:* SCP uses SSH for secure data transfer, which encrypts data during transfer.
  • Senzillaise:* SCP syntax is similar to elcp el syntax, which facilitates its use.
  • Compatibility:* It is available on most Unix and Unix-like systems, including Linux and macOS.

Steps to transfer files between teams

Here we show you how you can use SCP to transfer files quickly and securely.

Method

To make a file transfer between two teams, it is necessary:

  • An SCP client
  • That the remote equipment has an SSH server installed
  • Have the access credentials (IP, port, username and password) of the remote equipment
  • A folder or "path", within the remote computer, where the user has permissions to transfer the file

Practical examples with SCP

Copy files to a remote server

To transfer an archive from your computer to a remote server, use this command in the terminal (Linux or Mac):

scp archivo.txt usuario@host:/ruta/de/destino/

This command will send the file 'archive.txt' to the destination folder on the remote server.

Download Files from Remote Server

If you need to copy a file from the server to your computer, you can do it with this command:

scp usuario@host:/ruta/archivo_remoto.txt /ruta/destino/local/

This will download the file 'archiveremremot.txt' from the server to the local route on your computer.

Transfer Complete Directories

To copy a full folder, including all files and subfolders, you can use the '-r' option (recursive):

scp -r directorio usuario@host:/ruta/de/destino/

This will move the entire folder to the destination location on the server.

SCP using a specific port

If the remote server uses a port other than the standard port (22) for SSH, you can specify it with the --P- option:

scp -P puerto archivo usuario@host:/ruta/de/destino/

Only changes .port. by the number of the port used by the server.

cta:domains

Conclusion

Using Secure Shell (SSH) for file transfers offers a combination of security and efficiency that is difficult to overcome.

With SSH you can optimize your workflow and guarantee the integrity of your data during transfers.

In addition, understanding the role of SSH keys in authentication adds an additional layer of security to your operations on the server. With the right tools and knowledge at your disposal, you should find it easier to send files through SSH.

i
Email send icon