SFTP through the Terminal


Originally from http://kiri.dmt-uts.net

Accessing webserver through sftp through terminal

I've been using Cyberduck and FileZilla mostly for my FTP purposes up until this point, but since my MacBook Pro was reinstalled from scratch lately, since I moved off a HDD onto a SSD (solid state drive) I've been lacking a Java runtime environment, one which I haven't wanted to install, yet one that seems to be required everywhere - Cyberduck and FileZilla are no exceptions.

Thus I decided my last option was to use the terminal to SFTP, but either because I'd forgotten or just never known how, but I had to look it up to see exactly what commands I needed to use. Because I needed to specify a special port for SFTP, I had to write the following (Winterbottom, 2009):

sftp -oPort xxxx username@penguincoffee.net

What I didn't realise at the time, that I was in my Home folder, which meant that every time I wanted to specify where to fetch a file from, I had to point it to the right folder, then the right file, and then copy it over. I was using put (inputted file) (outputted file). I learned this command by being extraordinarily nosy and watching people work, so I can't reference anyone here.

put Pictures/penguincoffee/cat.jpg cat.jpg

The other issue is that when you SFTP in, you will be in the Home folder on your webserver, but you don't want to be placing files in that home folder, you want it in publichtml where it will be displayed online. Therefore you can use pwd, to print what directory you are currently in, and then use cd penguincoffee.net/publichtml for instance, to 'change your directory' and move into the publichtml folder. Because I have a folder called Images in my publichtml folder though, I might type cd penguincoffee.net/public_html/Images instead to change into there. If I have first moved into the destination folder of my original image, then I have moved into the outgoing destination where I want to copy it, I can just type:

put cat.jpg

And cat.jpg will be copied over to my webserver into the folder I am currently in, with the name cat.jpg. This file will overwrite another file called cat.jpg in that folder though, if I have one there.

It should be noted though, that since I'm with VentraIP, I needed to whitelist my IP address before it allowed me to access my webhosting from anywhere by SFTP, otherwise I could only ftp in, where the command is:

ftp username@ftp.penguincoffee.net

However ftp is insecure and should not be used if you can help it. It's strange that VentraIP should actively enforce not using SFTP by making it so difficult to set up though. In any case, the ftp url or IP address may be different in your case. It is suggested you should check emails from your provider or any other provided information from your provider for further details.

References:       Winterbottom, D. 2009, 'Connect via sftp to a specific port, viewed 24 March 2013, <http://www.commandlinefu.com/commands/view/2062/connect-via-sftp-to-a-specific-port>.