How can you migrate a website from one server to another? You have several options. One of the most common is to download the whole site to a computer and upload it to its new server. Or you could leverage third-party FTP tools to access both servers and move files between them, with your computer in the middle. But there’s another method you can try: transferring files over Secure Shell (SSH). We’ll explore how this works below.
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
Let’s find out how to use your Windows computer to connect to a remote Mac or Linux server (after you install Putty).
Use your remote servers’ web console to log in. Access their control panels and check that SSH is enabled. Follow these steps:
- 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.
- 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.
- 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.
- 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.
- Note your servers’ host key (for security purposes).
Start Putty and set up your SSH remote server connection.
- In the Configuration window, input the required details into the Host Name field.
- Make the connection.
- 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.
- 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!
- 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.
- Find the destination folder you’re looking for on the remote server (through Putty).
- 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.
- 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]
- “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).
- -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).
- 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] —
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!
You should find sending files over SSH easier after following this step-by-step guide.