Home  >  Article  >  Operation and Maintenance  >  How to set up remote file transfers (like SCP and SFTP) on Linux

How to set up remote file transfers (like SCP and SFTP) on Linux

PHPz
PHPzOriginal
2023-07-06 21:22:352662browse

How to set up remote file transfer (such as SCP and SFTP) on Linux

Remote file transfer plays an important role in the Linux system, which allows users to easily transfer files from the local host to the remote host, or download files from a remote host to a local computer. This article will introduce how to set up remote file transfer on Linux, including two common transfer protocols, SCP and SFTP.

1. SCP (Secure Copy)

SCP is a remote file transfer protocol based on the SSH protocol, which provides secure file transfer services. To use SCP for file transfer on Linux, you first need to ensure that the SSH service is installed and started. You can check the status of the SSH service through the following command:

$ service ssh status

If the SSH service is not started, you can use the following command to start it:

$ service ssh start

Next, we can use the SCP command to transfer the file from the local host Transfer to a remote host, or download files from a remote host to the local computer. The following is the basic usage of the SCP command:

Transfer files from local host to remote host:

$ scp /path/to/local/file username@remote_host:/path/to/remote/directory

Download files from remote host to local:

$ scp username@remote_host:/path/to/remote/file /path/to/local/directory

In the above command Among them, /path/to/local/file represents the path of the local file, username represents the user name on the remote host, remote_host represents the IP address of the remote host Or domain name, /path/to/remote/directory represents the directory where files are stored on the remote host, /path/to/remote/file represents the file path on the remote host, /path/to/local/directoryRepresents the directory where files are stored on the local host.

2. SFTP (SSH File Transfer Protocol)

SFTP is also a remote file transfer protocol based on the SSH protocol. It provides similar functions to SCP and supports more operations, such as uploading. Directory, download directory, etc. To use SFTP for file transfer on Linux, you also need to ensure that the SSH service is installed and started.

You can use the following command to start the SFTP client:

$ sftp username@remote_host

In the SFTP interactive interface, you can use a series of SFTP commands for file transfer and operations. The following are some commonly used SFTP commands:

Download files or directories from remote hosts to local:

get /path/to/remote/file     # 下载文件
get -r /path/to/remote/directory     # 下载目录及其内容

Upload local files or directories to remote hosts:

put /path/to/local/file     # 上传文件
put -r /path/to/local/directory     # 上传目录及其内容

View remote Files or directories on the host:

ls     # 列出当前目录下的文件和目录
ls /path/to/remote/directory     # 列出指定目录下的文件和目录

Delete files or directories on the remote host:

rm /path/to/remote/file     # 删除文件
rm -r /path/to/remote/directory     # 删除目录及其内容

Exit the SFTP client:

exit

With the above command, you can easily Set up remote file transfer on Linux without additional software tools or configuration. SCP and SFTP provide safe and reliable file transfer services and facilitate user operations. Hope this article helps you with remote file transfer on Linux.

The above is the detailed content of How to set up remote file transfers (like SCP and SFTP) on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn