Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Linux IntroductionChapter 7. SSH Remote Connection

SFTP (Secure File Transfer Protocol)

SFTP (Secure File Transfer Protocol)

Secure File Transfer with SFTP Protocol

SSH is used not only for remote login but also for file transfer in a secure way. There are two protocols to transfer files with SSH – SCP (Secure Copy Protocol) and SFTP (Secure File Transfer Protocol). In this section, we'll explain SFTP.

SFTP session and sub-commands

Unlike with SCP, after running the SFTP command, the SFTP session continues until you exit the session. Once the SFTP session is established, you can run sub-commands prepared for SFTP.

Establish SFTP session

There are two approaches to establishing an SFTP session – 1) without the SSH config file, and 2) with the SSH config file. The syntax is almost the same as the one of SSH. You can simply replace ssh with sftp.

Without the SSH config file, you need to specify the private key file path, user name, and IP address of the remote server.

Command Line - INPUT
sftp -i ~/.ssh/id_rsa ubuntu@54.169.91.239

With the SSH config file, the command is much simpler. Just type ssh and the SSH host name in your config file (the example below uses ssh_test as the SSH host name).

Command Line - INPUT
sftp ssh_test

Once the SFTP session is established, the command line changes to the one below.

Command Line - INPUT
   

SFTP sub-commands

During an SFTP session, you can run several SFTP sub-commands.

Check and change directories

SFTP provides sub-commands to check and change directories under both the remote server and the local computer. Here are the examples.

SFTP sub-commands

get command – download a file or directory from the remote server

Once you set the current working directory on both the local computer and remote server, you can download the file from the remote server to the local computer with the get command.

For example, by running the command below, you'll transfer the sample.txt file under the current working directory on the remote server to the current working directory of your local computer.

Command Line - INPUT
get sample.txt

This is the illustration of the file transfer.

SFTP get command – download a file or directory from the remote server

If you want to download a directory, use the -r option.

Command Line - INPUT
get -r sample_dir

put command – upload a file or directory to the remote server

To upload a file or directory from your local computer to the remote server, you can run the put command.

For example, by running the command below, you'll transfer the test.txt file under the current working directory on your local computer to the current working directory of the remote server.

Command Line - INPUT
put test.txt

exit (bye) command – stop the SFTP session

To end the session, run the exit (or bye) command.

Command Line - INPUT
exit

help command – check SFTP sub-commands

If you want to know more about SFTP sub-commands, the help command can be useful. It gives you a list of available SFTP sub-commands.

IdeaNote: Difference between SCP and SFTP

One of the major differences between SCP and SFTP is while the SFTP protocol can resume data transfer which was stopped for some reason, SCP cannot resume it. To resume data transfer with SFTP, use the reget command.

For example, if you want to resume the sample_dir transfer, you can run the command below.

Command Line - INPUT
reget -r sample_dir

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Creating a GitHub Account

Create GitHub Account

Advanced Container Lifecycle Management

Advanced Container Lifecycle Management

Introduction to systemd

Systemd

Setting Up Linux Environment on AWS

Setting Up Linux Environment on AWS

Combining Commands with Pipe

Pipe (Combine Commands)

Creating a GitHub Account

Create GitHub Account

Advanced Container Lifecycle Management

Advanced Container Lifecycle Management

Introduction to systemd

Systemd

Setting Up Linux Environment on AWS

Setting Up Linux Environment on AWS

Combining Commands with Pipe

Pipe (Combine Commands)

Tags:

SSH

Remote Connection

SFTP

Linux Introduction
Course Content

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server