How to Transfer Files Between Servers Using SSH and SCP

If you’re looking to migrate a website from one server to another, you might not have considered an SSH file transfer. After all, you’ve got options. Another popular method involves downloading the entire site to your computer and then uploading it to the new server. Or you could use third-party FTP tools to access both servers and move files between them. But the more efficient and secure approach you might not have considered is transferring files over Secure Shell (SSH). Let’s explore how this method works and why it might be the ideal solution for your migration needs.

 

Table of Contents

 

What Is SSH and Why Use It for File Transfers?

The SSH file transfer protocol relies on SSH, which is a secure network protocol that allows you to utilize network services securely by creating a safe channel on an unsecured network. But it operates through the command line, as opposed to the majority of third-party FTP applications. You can choose either the Windows Command Prompt or Terminal in Mac and Linux systems to use SSH.

Does your version of Windows predate Windows 10? A third-party app is necessary to take advantage of SSH, as it only became native with that version. In cases like these, Putty is the most widely used SSH app for Windows. You can find it at https://www.putty.org/.

SSH is a native feature in Mac and Linux systems, though, so you can use it straight out of the box. And as most servers run on Linux, SSH should be available natively — unless your server is on Internet Information Service (IIS), the Windows equivalent.

As a result, you won’t need to install third-party apps (except Putty) to follow the below guide.

What Is SCP (Secure Copy Protocol) and How Does It Work with SSH?

Performing an SSH file transfer typically uses the SCP protocol—a method for securely transferring files and folders between computers. SCP is based on the SSH protocol, which provides the secure connection.

A client can use an SCP to upload files to a remote server safely, download files, or even transfer files over SSH across remote servers. We’ll focus on this below.

How to Transfer Files Between Remote Servers Using SSH and SCP (3 Easy Steps)

Let’s find out how to use your Windows computer to connect to a remote Mac or Linux server so you can perform an SSH file transfer.

Step 1: Enable SSH Access on Your Remote Servers

Use your remote servers’ web console to log in. Access their control panels and check that SSH is enabled. Follow these steps:

  1. SSH tends to be disabled initially as standard, so you might need to enable it. If you don’t know how to do that, look at the documentation for your server OS or contact the provider’s support service.
  2. Make a note of the SSH username assigned: this will either be created by you or the server, depending on the server’s operating system.
  3. Enter the password twice (to confirm) to finish creating your SSH account — you can change the password, but servers have their own methods for doing so.
  4. Make a note of the Secure Shell Connection Information — you’ll need this to connect to the remote server when you utilize the SSH client.
  5. Note your servers’ host key (for security purposes).

Step 2: Connect to Your Remote Server via SSH Using PuTTY

Transferring files via SSH across remote servers is made simple with PuTTY, a versatile Windows application renowned for its secure connection capabilities and seamless file transfer functionalities. For this process, you´ll need to start by installing PuTTY

Start PuTTY and set up your SSH remote server connection.

  1. In the Configuration window, input the required details into the Host Name field.
  2. Make the connection.
  3. PuTTY will show you a security warning if this is the first time you’re connecting to a server.  But if it’s NOT the first time and you still receive the alert, be careful. It might be that a hacker has targeted you with a Man-In-The-Middle attack, trying to occupy your connection and take your password.
  4. Feel satisfied that it’s an authentic connection? Click the Yes button. PuTTY will display a terminal window, and prompt you to enter your username followed by your password. Input your information. There’s no on-screen response when you enter passwords over SSH. Just put your password in and tap the Enter button!
  5. When you enter your password correctly, the terminal window presents a command line on the server. You can enter commands into this terminal window, and enjoy limited server control. All server responses are visible in this window.

Step 3: Use SCP to Transfer Files Between Remote Servers Over SSH

  1. Find the destination folder you’re looking for on the remote server (through PuTTY).
  2. Check the folder’s contents to make sure none of its files or folders have been given an identical name to the files or folders you intend to transfer. If they have been, try to rename or delete them, or relocate them to a different folder.
  3. With Secure Copy, transfer files from server to server. Here’s the Secure Copy syntax (“scp” enables the function): scp [switch] [source content location] [destination content location]
  4. “Switch” is optional. If you want to transfer a file over SSH (one only), or several stored in a directory and intended to share the same folder, you WON’T require a switch. But you WILL need one if you plan to transfer whole folders, and that is the “recursive switch” (-r).
  5. -r is not the only switch available — you can use many others to control SCP (but we won’t go into them in this guide).
  6. The Content Location syntax differs based on its location. For content found on the server you’re logged into, the location is the directory or filename you want to use. For example, “/var/www/dir”. But for content stored on the second remote server that you’re not logged into, things get a little more complex. For example,

[userid]@[remote server 2 url or ip address]:[directory or file] — [email protected]:/var/www/

So, a complete example of the syntax you need for transferring a directory from remote server to remote server would look like this (if the destination is the server you’re logged into at present):

scp - r [email protected]:/var/www/var/www/dir

You’ll be asked to put your password in for the second remote server. You won’t see it appear as you enter your password, as before. When you’re done, hit Enter.

You’ll see the file transference process begin if you have entered the right password for the second remote server. Now, you can shut the terminal window: the transfer will carry on automatically!

Conclusion: Why SSH and SCP Are the Best Tools for Secure File Transfer

Utilizing Secure Shell (SSH) for file transfers offers a combination of security and efficiency that is hard to beat. With SSH you can streamline your workflow and ensure the integrity of your data during transfers. Additionally, understanding the role of SSH keys in authentication adds an extra layer of security to your server operations. For a comprehensive guide on SSH keys and how to use them effectively, check out our article “SSH Keys: A Guide for Beginners.” With the right tools and knowledge at your disposal, you should find sending files using the SSH file transfer easier.

Frequently Asked Questions

SCP (Secure Copy Protocol) and SFTP (SSH File Transfer Protocol) both use SSH for secure file transfers, but SCP is faster and simpler for one-way file transfers. SFTP offers more advanced features like directory listings and file management.

Yes, SCP allows you to transfer files directly between two remote servers without downloading them to your local machine. This is done by logging into one server and specifying the other server in the SCP command. 

SSH is built into Windows 10 and later versions. For older Windows systems, you need to use a third-party application like PuTTY to enable SSH functionality. 

You can check your server settings via its control panel or web console. Look for SSH access options. If unsure, consult your hosting provider’s documentation or support team.

PuTTY is a free SSH and telnet client for Windows. It’s commonly used to securely connect to remote servers when native SSH support is unavailable or limited.

Not directly with SCP. If you need to resume large or interrupted file transfers, consider using rsync over SSH, which has resume capabilities.

No, both Linux and macOS have built-in support for SSH and SCP via the terminal, so no additional software is required.

4 Comments

  1. May I know if you guys will actually recommend the SCP command or the RSYNC command in this case?

  2. Hi
    Excusme, Can you send me pictuer how transfer file.jar to the server.
    thank you.

Add a Comment

Your email address will not be published. Required fields are marked *

GET LATEST NEWS AND TIPS

  • Yes, please, I agree to receiving my personal Plesk Newsletter! WebPros International GmbH and other WebPros group companies may store and process the data I provide for the purpose of delivering the newsletter according to the WebPros Privacy Policy. In order to tailor its offerings to me, Plesk may further use additional information like usage and behavior data (Profiling). I can unsubscribe from the newsletter at any time by sending an email to [email protected] or use the unsubscribe link in any of the newsletters.

  • This field is hidden when viewing the form
  • This field is hidden when viewing the form
  • This field is hidden when viewing the form
  • This field is hidden when viewing the form
  • This field is hidden when viewing the form
  • This field is hidden when viewing the form

Related Posts

Knowledge Base