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

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

centos7.2 offline installation mysql5.7.18.tar.gz

Because of network isolation, MySQL cannot be ins...

CSS3 realizes the mask barrage function

Recently I saw a barrage effect on B station call...

Tips for optimizing MySQL SQL statements

When faced with a SQL statement that is not optim...

MySQL 5.7.17 and workbench installation and configuration graphic tutorial

This article shares the installation and configur...

How to install mongodb 4.2 using yum on centos8

1. Make a repo file Refer to the official install...

How to configure mysql5.6 to support IPV6 connection in Linux environment

Introduction: This article mainly introduces how ...

Solution to the problem that mysql local login cannot use port number to log in

Recently, when I was using Linux to log in locall...

Summary of Mysql exists usage

Introduction EXISTS is used to check whether a su...

How to build a private Docker repository using Harbor

Table of contents 1. Open source warehouse manage...

How to install grafana and add influxdb monitoring under Linux

Install grafana. The official website provides an...

HTML form_PowerNode Java Academy

1. Form 1. The role of the form HTML forms are us...

How to implement function currying and decurrying in Javascript

Function currying (black question mark face)? ? ?...