Secure File Transfer Protocol (SFTP)
- Sometimes you need to transfer files between two computers.This can take the form of either transferring files from you local computer to your remote server or from your remote computer back to your local computer.
- Before we had more mature continuous deployment tools like Azure Pipelines, Travis CI, or GitHub Actions, we often used a tool called ftp (file transfer protocol).
- While it worked and it was a relatively simple and straightforward of doing things, we moved onto to more reliable tools. However ftp evolved into secure ftp which we still use today.
How to set up SFTP?
One of the best things about sftp is that it works 100% over the same ways that ssh does so if you've set up ssh you've inherently set up sftp too (it possible to set up one and not the other but you have change some options.) This was a welcome departure from ftp which has its own setup process and ports that had to be managed.
info
The thing to keep in mind is you're in two directories at the same time as opposed to normal bash when you're just in one. With sftp, you have a local context and a remote context.
- In order to run a local command, tack an
l
to the start of whatever command you're running, likells
,lpwd
, orlcd
. - When you want to do it on the remote machine, just run the commands like normal, like
ls
,pwd
, orcd
.
sftp brian@<the same ip from the previous step>
lpwd # ubuntu's local home directory
pwd # brian's remote home directory
lls # the list of files in ubuntu's home directory
ls # the list of files in brian's home directory
help # see all the commands you can do
The two key commands you need to know here are get
and put
.
-
get
Getting something will download it from secondary -
put
putting something will upload it.get file.txt # download file.txt from the remote machine
put file.txt # upload file.txt to the remote machine