10 scp commands to transfer file folders in Linux
Basic usage of scp command
The following command means Copy source_file_name
to destination_folder
under username account
of destination_host
.
> scp source_file_name username@destination_host:destination_folder
copy
There are many parameters that can be used in the scp
command. The following are some parameters that may be used in daily operations.
Use the -v
parameter to display detailed information of the scp process
The default scp
command takes no parameters and will copy files silently in the background. Users only see the results when the process is complete or when an error occurs.
You can use the -v
parameter to output debugging information to the screen. This can help you troubleshoot connectivity, authentication, and configuration issues.
rumenz@local $ scp -v Label.pdf rumenz@192.168.1.110:.
Output
scp displays progress when copying files
Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -t . OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to 202.x.x.x [202.x.x.x] port 22. debug1: Connection established. debug1: Host '202.x.x.x' is known and matches the RSA host key. debug1: Found key in /home/pungki/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: Next authentication method: password rumenz@202.x.x.x's password: debug1: Authentication succeeded (password). Authenticated to 202.x.x.x ([202.x.x.x]:22). Sending file modes: C0770 3760348 Label.pdf Sink: C0770 3760348 Label.pdf Label.pdf 100% 3672KB 136.0KB/s 00:27 Transferred: sent 3766304, received 3000 bytes, in 65.2 seconds Bytes per second: sent 57766.4, received 46.0 debug1: Exit status 0
Provide the modification time, access time and mode of the original file
The-p
parameter will help you solve this problem. An estimated time and connection speed will appear on the screen.
rumenz@local $ scp -p Label.pdf rumenz@192.168.1.110:.
Output
scp Estimate the time required to copy large files
> rumenz@202.x.x.x's password: Label.pdf 100% 3672KB 126.6KB/s 00:29
Use the -C parameter to speed up file transfer
One of the parameters that can speed up file transfers is the -C
range. This -C
parameter will compress your files anytime and anywhere, the unique thing is that compression only happens on the network. When the file reaches the destination server, it is restored to its original size before compression.
> rumenz@local $ scp -pv messages.log rumenz@192.168.1.110:.
Output
scp Transfer files without compression
Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -p -t . OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to 202.x.x.x [202.x.x.x] port 22. debug1: Connection established. debug1: identity file /home/pungki/.ssh/id_rsa type -1 debug1: Found key in /home/pungki/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: Trying private key: /home/pungki/.ssh/id_rsa debug1: Next authentication method: password rumenz@202.x.x.x's password: debug1: Authentication succeeded (password). Authenticated to 202.x.x.x ([202.x.x.x]:22). debug1: Sending command: scp -v -p -t . File mtime 1323853868 atime 1380425711 Sending file timestamps: T1323853868 0 1380425711 0 messages.log 100% 93MB 58.6KB/s 27:05 Transferred: sent 97614832, received 25976 bytes, in 1661.3 seconds Bytes per second: sent 58758.4, received 15.6 debug1: Exit status 0
-C
Allow compression
rumenz@local $ scp -Cpv messages.log rumenz@192.168.1.110:.
Output
scp Transfer files faster using compression
Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -p -t . OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to 202.x.x.x [202.x.x.x] port 22. debug1: Connection established. debug1: identity file /home/pungki/.ssh/id_rsa type -1 debug1: Host '202.x.x.x' is known and matches the RSA host key. debug1: Found key in /home/pungki/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: Next authentication method: publickey debug1: Trying private key: /home/pungki/.ssh/id_rsa debug1: Next authentication method: password rumenz@202.x.x.x's password: debug1: Enabling compression at level 6. debug1: Authentication succeeded (password). Authenticated to 202.x.x.x ([202.x.x.x]:22). debug1: channel 0: new [client-session] debug1: Sending command: scp -v -p -t . File mtime 1323853868 atime 1380428748 Sending file timestamps: T1323853868 0 1380428748 0 Sink: T1323853868 0 1380428748 0 Sending file modes: C0600 97517300 messages.log messages.log 100% 93MB 602.7KB/s 02:38 Transferred: sent 8905840, received 15768 bytes, in 162.5 seconds Bytes per second: sent 54813.9, received 97.0 debug1: Exit status 0 debug1: compress outgoing: raw data 97571111, compressed 8806191, factor 0.09 debug1: compress incoming: raw data 7885, compressed 3821, factor 0.48
If you are copying a large number of files over the network, the -C
parameter will help you reduce the total time required.
压缩方法不适用于所有文件。当源文件已经被压缩时,就没有什么效果了。文件如.zip
,.rar
,pictures
, 和.iso
更改 scp 密码以加密文件
默认情况下scp
使用 AES-128
来加密文件。如果你想更改为其他密码对其进行加密,你可以使用 -c
范围。看看这个命令。
rumenz@local $ scp -c 3des Label.pdf rumenz@192.168.1.110:. rumenz@202.x.x.x's password: Label.pdf 100% 3672KB 282.5KB/s 00:13
上面的命令告诉scp
使用3des algorithm
来加密文件。请注意此参数使用 -c
不是-C
。
使用 scp 命令限制带宽使用
另一个可能有用的参数是 -l
范围。这 -l
参数将限制使用的带宽制 。如果你执行自动化脚本来复制大量文件,这将很有用
rumenz@local $ scp -l 400 Label.pdf rumenz@192.168.1.110:. rumenz@202.x.x.x's password: Label.pdf 100% 3672KB 50.3KB/s 01:13
scp 默认带宽的单位是Kilobyte/sec
(KB/s
)。所以如果你想限制你的带宽scp
最多只有50 KB/s
,你需要将其设置为50 x 8
=400
.
指定要与 scp 一起使用的特定端口
scp
正在使用端口22
作为默认端口。但出于安全原因,你可以将端口更改为另一个端口. 例如,我们使用端口2249
.
rumenz@local $ scp -P 2249 Label.pdf rumenz@192.168.1.110:. rumenz@202.x.x.x's password: Label.pdf 100% 3672KB 262.3KB/s 00:14
递归复制目录中的文件
有时我们需要复制目录和其中的所有文件
,目录
。
rumenz@local $ scp -r documents rumenz@192.168.1.110:. rumenz@202.x.x.x's password: Label.pdf 100% 3672KB 282.5KB/s 00:13 scp.txt 100% 10KB 9.8KB/s 00:00
复> 制过程完成后,你将在目标服务器上找到一个名为documents
及其所有文件。文件夹documents
是自动创建的。
禁用进度表和警告 / 诊断消息
rumenz@local $ scp -q Label.pdf rumenz@192.168.1.110:. rumenz@202.x.x.x's password: rumenz@local $
可以看到,输入密码后,没有关于 scp 进程的信息。该过程完成后,你将再次看到提示。
通过代理使用 scp 复制文件
代理服务器通常用于办公环境。scp 本身没有配置代理。当你的环境使用代理时,你必须告诉scp 与代理进行通信。
例如代理地址是10.0.96.6
代理端口是8080
.代理还实现了用户身份验证。首先,你需要创建 ~/.ssh/config
文件
ProxyCommand /usr/bin/corkscrew 10.0.96.6 8080 %h %p ~/.ssh/proxyauth
然后你需要创建文件 ~/.ssh/proxyauth
里面输入。
myusername:mypassword
前提是需要安装corkscrew
$ apt-get install corkscrew
Centos系统可以用yum
安装corkscrew
# yum install corkscrew
由于 ~/.ssh/proxyauth
文件包含你的 username
和password
以明文格式,请确保该文件只能自己访问。
选择不同的ssh_config 文件
对于经常在公司网络和公共网络之间切换的移动用户来说,总是在scp中更改设置会很痛苦。
场景示例
代理在公司网络中使用,但不在公共网络中使用,并且你定期切换网络。
rumenz@local $ scp -F /home/pungki/proxy_ssh_config Label.pdf rumenz@192.168.1.110:. rumenz@202.x.x.x's password: Label.pdf 100% 3672KB 282.5KB/s 00:13
默认情况下 ssh_config
每个用户的文件将被放置在 ~/.ssh/config
。创建一个特定的 ssh_config
具有代理兼容性的文件将更容易在网络之间切换。
当你在公司网络,你可以使用 -F
范围。当你在公共网络上时,你可以不用-F
参数。
The above is the detailed content of 10 scp commands to transfer file folders in Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

CentOS installation steps: Download the ISO image and burn bootable media; boot and select the installation source; select the language and keyboard layout; configure the network; partition the hard disk; set the system clock; create the root user; select the software package; start the installation; restart and boot from the hard disk after the installation is completed.

CentOS has been discontinued, alternatives include: 1. Rocky Linux (best compatibility); 2. AlmaLinux (compatible with CentOS); 3. Ubuntu Server (configuration required); 4. Red Hat Enterprise Linux (commercial version, paid license); 5. Oracle Linux (compatible with CentOS and RHEL). When migrating, considerations are: compatibility, availability, support, cost, and community support.

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)
