How To Transfer Files Between Servers Using SSH

Looking to migrate a website from one server to another? You’ve got options. One 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 there’s a more efficient and secure approach you might not have considered: 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.

What is SSH?

SSH 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 Secure Copy Protocol (SCP)?

Sending files over SSH relies on the SCP protocol: this is a technique for transferring files and folders from computer to computer securely. It’s based on the SSH protocol used with it.

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

Transferring Files Via SSH Across Remote Servers: a 3-Step Process

Let’s find out how to use your Windows computer to connect to a remote Mac or Linux server.

Step One: Checking and Enabling SSH on 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 Two: Setting Up SSH Remote Server Connection with 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 Three: Transferring Files Between Remote Servers Using Secure Copy (SCP):

  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

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 over SSH easier.

 

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.

  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden

Related Posts

Knowledge Base

Plesk uses LiveChat system (3rd party).

By proceeding below, I hereby agree to use LiveChat as an external third party technology. This may involve a transfer of my personal data (e.g. IP Address) to third parties in- or outside of Europe. For more information, please see our Privacy Policy.

Search
Generic filters
Exact matches only
Search in title
Search in content
Search in excerpt