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!

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

Introduction: Securing the Digital Frontier with Linux-Based Ethical Hacking In our increasingly interconnected world, cybersecurity is paramount. Ethical hacking and penetration testing are vital for proactively identifying and mitigating vulnerabi


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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor