How to transfer data in a Linux system

The scp command is used for remote file copying in Linux. It allows copying files or directories between multiple Linux systems, similar to the functionality of the cp command. But instead of local copying, it operates to another host over the network.

Syntax format: scp [parameters] file_or_directory [remote_server_info]

Common parameters:

-1:Use SSH protocol version 1;

-2:Use SSH protocol version 2

-4:Use ipv4

-6:Use ipv6

-B:Run in batch mode;

-C:Use compression;

-F:Specify the SSH configuration file;

-iidentity_file Read the key file used for the transfer from the specified file (e.g., Amazon Cloud .pem file); this parameter is passed directly to SSH

-l:Specify bandwidth limit;

-o:Specify the SSH options to use;

-P:Specify the port of the remote host;

-p:Preserve the file's last modification time, last access time, and permission mode;

-q:Do not display the copy progress;

-r:Copy recursively。

 

Parameters

  • Source file: Specify the source file to be copied.
  • Destination file: The target file. The format is user@host:filename (where filename is the name of the target file).

 

Example

The scp command to copy from remote to local is similar to the one above; you just need to swap the order of the last two parameters.

1.Copy files from a remote machine to the local directory

scp [email protected]:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/

Download the nginx-0.5.38.tar.gz file from the /opt/soft/ directory on the machine 10.10.10.10 to the local /opt/soft/ directory.

 

2.Copy OpenVPN from Amazon Cloud to the local directory

scp -i amazon.pem [email protected]:/usr/local/openvpn_as/etc/exe/openvpn-connect-2.1.3.110.dmg openvpn-connect-2.1.3.110.dmg

Download the OpenVPN installation file from the machine 10.10.10.10 to the current local directory.

3.Copy from a remote machine to the local machine

scp -r [email protected]:/opt/soft/mongodb /opt/soft/

Download the mongodb directory from /opt/soft/ on the machine 10.10.10.10 to the local /opt/soft/ directory.

 

4.Upload a local file to a specified directory on a remote machine.

scp /opt/soft/nginx-0.5.38.tar.gz [email protected]:/opt/soft/scptest

# Specify the port 2222

scp -rp -P 2222 /opt/soft/nginx-0.5.38.tar.gz [email protected]:/opt/soft/scptest

Copy the nginx-0.5.38.tar.gz file from the local /opt/soft/ directory to the /opt/soft/scptest directory on the remote machine 10.10.10.10.

 

5.Upload a local directory to a specified one on a remote machine.

scp -r /opt/soft/mongodb [email protected]:/opt/soft/scptest

Upload the local directory /opt/soft/mongodb to the /opt/soft/scptest directory on the remote machine 10.10.10.10.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

CentOS 7.x Firewall: Enable/Disable and Add Ports

  In CentOS 7.x, the default firewall is firewalld. Here is an example using CentOS 7.6...

How to enable/disable ping on Linux system

To prevent others from discovering and potentially attacking your machine through network ping...

How to View Memory Usage and Clear Cache in Linux System

Sometimes, when a server becomes unresponsive, it may not necessarily be due to high CPU usage....

How to remotely access a Linux system using Putty tool

Introduction to Putty software PuTTY is a Telnet, SSH, rlogin, raw TCP, and serial interface...

Linux System RuiSu Installation Tutorial

Note: The prerequisite for installing RuiSu is to ensure that the network card is in the "eth"...