Detailed explanation of scp and sftp commands under Linux

Detailed explanation of scp and sftp commands under Linux

Preface

scp and sftp are remote file encryption transfer protocols. In layman's terms, they are used to操控本地/遠程文件. Did you notice that they both start with s ? Yes, they have a layer of ssh encryption protocol nested inside them.
The traditional version of sftp is ftp , but this protocol is not secure. The transmitted data is all in plain text and is easily attacked and stolen. That's why sftp was developed later. In fact, it is the same as http/https.
If you haven't learned about ssh yet, you can refer to what I wrote before about what ssh is and what it is used for. It doesn't matter if you don't want to understand it, because these two commands are very simple to use. Let's get into the main text.

1. scp usage

The basic command of scp is: scp socure target

1.1 Copy local files to the remote machine

Example 1
scp -r ./test/ [email protected]:/home/
Example 2
scp -P 6666 -r ./test/ [email protected]:/home/

The -r parameter indicates whether to recursively copy the directory
The -P parameter specifies the ssh port number (note that it is capital P)
The above means putting the local ./test directory under /home/ on the remote machine

1.2 Copy the remote machine file to the local

Example: scp -r [email protected]:/home/test ./home/

The above means to put the remote machine's /home/test directory under the local ./home/

1.3 Copy a remote file to another remote machine

Example: scp -r [email protected]:/home/test [email protected]:/home/

The above means to put the remote machine's /home/test directory under another remote machine's /home/

2. Use sftp

First, we open git or linux to connect to the server

If you are using a Windows system, you can also try to enter it, because some Windows systems such as Win10 already have it built-in

Format sftp username@hostname
For example, sftp [email protected]

Next you will enter the sftp command mode

sftp> Enter your sftp command

1.1 Copy local files to the remote machine

Format: put localfile [remotefile]
Example: put -r ./test /home

The -r parameter indicates whether to copy recursively

1.2 Copy the remote machine file to the local

Format get remotefile [localfile]
Example get -r /home/test ./home

1.3 Create/delete remote directories

Create a hello directory mkdir hello
Delete the hello directory rmdir hello

The sftp remote work environment defaults to the user directory, so the hello directory created above will be placed under ~/hello . Assuming your username is root, it will be in root/hello . To change the environment, you can use cd or add an absolute path / identifier, as follows

The first cd /home
mkdir hello
The second type is mkdir /home/hello

3. What is the difference between scp and sftp? Which one is better?

the difference
1. scp can copy remote files to another remote machine, but sftp cannot
2. scp does not have the function of deleting/creating remote directories, but sftp does

Which one is better? <br /> If you need to operate files occasionally, use scp , otherwise sftp

Okay, that’s all for now.

Summarize

This is the end of this article about the detailed usage of scp and sftp commands under Linux. For more relevant content about linux scp and sftp commands, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed introduction to Linux commands scp and sftp

<<:  Html sample code for reading and displaying pictures in a local folder

>>:  Do you know the meaning of special symbols in URL?

Recommend

Detailed discussion of the character order of mysql order by in (recommended)

//MySQL statement SELECT * FROM `MyTable` WHERE `...

Introduction to Enterprise Production MySQL Optimization

Compared with other large databases such as Oracl...

Rhit efficient visualization Nginx log viewing tool

Table of contents Introduction Install Display Fi...

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

Start a local Kubernetes environment using kind and Docker

introduce Have you ever spent a whole day trying ...

JS realizes picture digital clock

This article example shares the specific code of ...

Native JS implements a very good-looking counter

Today I will share with you a good-looking counte...

Circular progress bar implemented with CSS

Achieve results Implementation Code html <div ...

Docker nginx + https subdomain configuration detailed tutorial

Today I happened to be helping a friend move his ...

Vue implements an Input component that gets the key display shortcut key effect

I encountered a requirement to customize shortcut...

Example code for configuring monitoring items and aggregated graphics in Zabbix

1. Install Zabbix Agent to monitor the local mach...

Use of Linux tr command

1. Introduction tr is used to convert or delete a...

Solution to mysql failure to start due to insufficient disk space in ubuntu

Preface Recently, I added two fields to a table i...

mysql-8.0.17-winx64 deployment method

1. Download mysql-8.0.17-winx64 from the official...

MySQL automatically inserts millions of simulated data operation code

I use Navicat as my database tool. Others are sim...