FTP Transfer using SSH

Yesterday I learned how to migrate to a new web host in a very satisfyingly geeky way. If you are on Mac OS open up Terminal (enable the Homebrew theme) dim the lights, or block them out if possible, stick on the Matrix Soundtrack from 1998 and prepare to login to SSH! Its command line and slightly overwhelming.

SSH gives a user access to a remote machine so you can run commands on that server… as if you were in the room. Like scren sharing in the command line. When migrating loads of files from one remote place to another this is great as it saves us a step. Rather than transferring gigabytes of data from one remote server to our local machine to then forward on to another remote machine we just login and get the two remote machines to sort it out between themselves. Up here in the Scottish Highlands I’m on a community owned broadband network and I’m almost certain our local internet guru would have something to say about 100’s of gigabytes flying around so that was my reason for stumbling upon this magic code.

Here’s how– note I’m writing this as a backup for myself in the future. I am not an expert. With that proviso stamp into your command line something like:

ssh -oPort=65002 username@123.456.789.777

In this example my server IP is 123.456.789.777, the port to access this server is 65002. I know this because my host tells me so. Check you don’t need to whitelist your IP or download complex security certificates before trying this. I was locked out for 12 hours as I made a tonne of badly formatted requests, there was no notification that I was locked out, I found out through a very long-winded chat with customer service… anyway.

You’ll next enter your password for that server. Then you’re in!

UNIX – I know this!

Now that you’ve logged into one remote machine (in my case this was the new web host- Hostinger) you can use UNIX-y type commands to navigate around. For example:

ls

Which will list the contents of the current directory, then the command:

cd

moves you around, like this:

cd /public_html/

Let us assume I’ve located the directory I want to work in. Next its the really fun bit where I use this SSH instance to login to another server. Remember its the external SSH connected server that’s connecting to the server, not your local computer. You’re essentially screen sharing.

I logged in like this (to my shitty old web host- Bluehost):

sftp -P 22 callumal@123.456.789.777

Another password and you’re in. I did some digging around and found an excellent command to move directories, with my network dropping a few times yesterday I discovered a way to recover when things went pear shape. Here’s the final bit of magic:

get -a -R /public_html/some_directory/

That’ll move /some_directory/ form the shitty old web host to the sparkling new one (working directory was /public_html). If the connection fails, run the command again and it’ll eventually pick up where it left off. The -R makes it ‘recursive’, so all directories inside /public_html/ are moved also. Then logoff and get on with your day.

logout

Leave a Reply