Insight: Getting Started with SFTP File Transfers on Ubuntu


Insight: Getting Started with SFTP File Transfers on Ubuntu








Welcome to the world of Ubuntu! As you explore this powerful operating system, you'll often encounter the need to securely transfer files between your machine and a remote server. That's where SFTP (SSH File Transfer Protocol) comes in handy. Think of it as a secure and encrypted way to manage files online, just like using a file explorer on your computer, but for remote servers.


What is SFTP?

Simply put, SFTP is a secure method for accessing and managing files on a remote server. Unlike the older FTP protocol, SFTP encrypts your commands and data, protecting your information as it travels across the internet. This makes it the preferred choice for transferring sensitive data.


SFTP vs. SSH

It's important to understand that SFTP is built upon SSH (Secure Shell). SSH provides the secure, encrypted connection, and SFTP uses that connection to transfer files. Think of SSH as the secure tunnel, and SFTP as the file transfer protocol that travels through that tunnel. You can use SSH for other things, like running commands on a remote server, but SFTP's sole purpose is secure file transfer.


Connecting to a Remote Server

To get started with SFTP, you'll need a few things:
  • The address (hostname or IP address) of the remote server. This is like the website address for the server you want to connect to.
  • Your username for that server. This identifies your account on the remote system.
  • Your password or a private key. This is your secure way to prove your identity.
Once you have this information, open your Ubuntu terminal (you can usually find it by searching for "Terminal" in the application menu). The basic command to connect is:

Bash
sftp username@remote_server_address   

Let's say your username is newbie and the server address is myserver.com. You would type:

Bash
sftp newbie@myserver.com   

Press Enter, and you'll likely be prompted for your password:

Bash
newbie@myserver.com's password:   

Type your password (it won't be displayed on the screen for security reasons) and press Enter. If your credentials are correct, you'll see an sftp> prompt, indicating you're now connected to the remote server!

Bash
sftp>   


Basic SFTP Commands

Once connected, you can use various commands to navigate and manage files. Here are a few essential ones:

ls: Lists the files and directories on the remote server (similar to the regular ls command in your Ubuntu terminal).


Bash
sftp> ls 
file1.txt folder1 image.jpg 
sftp>   

cd: Changes the current directory on the remote server (like the cd command in your terminal).

Bash
sftp> cd folder1 
sftp> ls 
another_file.txt 
sftp>   

pwd: Shows your current working directory on the remote server.

Bash
sftp> pwd 
Remote working directory: /home/newbie/folder1 
sftp>   

get: Downloads a single file from the remote server to your local Ubuntu machine.

Bash
sftp> get remote_file.txt 
Fetching /home/newbie/remote_file.txt to remote_file.txt 
sftp>   

get -r: Downloads a directory and all its contents from the remote server to your local Ubuntu machine. The -r option makes the get command work recursively, meaning it will download the directory and everything inside it.

Bash
sftp> get -r remote_directory 
Fetching /home/newbie/remote_directory to remote_directory 
sftp>   

put: Uploads a single file from your local Ubuntu machine to the remote server.

Bash
sftp> put local_document.pdf 
Uploading local_document.pdf to /home/newbie/local_document.pdf 
sftp>   

put -r: Uploads a directory and all its contents from your local Ubuntu machine to the remote server. The -r option again makes the put command work recursively.

Bash
sftp> put -r local_directory 
Uploading local_directory to /home/newbie/local_directory 
sftp>   

bye or exit: Disconnects from the remote server and closes the SFTP session.

Bash
sftp> bye
Bye


A Quick Recap

SFTP, built on the secure foundation of SSH, is your secure friend for transferring files with remote servers. By using simple commands like lscdget (and get -r for directories), and put (and put -r for directories), you can easily manage your online files and directories right from your Ubuntu terminal.

This is just a starting point, of course! As you become more comfortable, you can explore more advanced SFTP options. But for now, you have the basics to get you started. Happy transferring!


Need Ubuntu Expertise?

We'd love to help you with your Ubuntu projects.  Feel free to reach out to us at info@pacificw.com.


Written by Aaron Rose, software engineer and technology writer at Tech-Reader.blog.

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

The Reasoning Chain in DeepSeek R1: A Glimpse into AI’s Thought Process